您可以尝试如下代码:
bool allEmpty = true;
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < fpSpread2.ActiveSheet.ColumnCount; i++)
{
for (int j = 0; j < fpSpread2.ActiveSheet.RowCount; j++)
{
if(fpSpread2.ActiveSheet.Cells[i, j].Value != null)
{
allEmpty = false;
break;
}
}
if (allEmpty)
{
fpSpread2.ActiveSheet.Columns.Visible = false;
//fpSpread2.ActiveSheet.Cells[0,i].RowSpan = fpSpread2.ActiveSheet.RowCount;
}
allEmpty = true;
}
} |