【发布时间】:2015-02-06 05:31:44
【问题描述】:
我正在使用 csharp 将数据插入到 Excel 工作表中,分为 7 列。该程序的界面将允许用户选择 7 个复选框。如果他们选择全部 7 个,则 spreadhseet 中的所有 7 列都会有数据,如果他们选择一个复选框,那么只有一列会有数据。我有一个 for 循环,它将检查数据是否存在,如果不存在数据,我想删除 epplus 中的该列。这是之前关于这个主题的讨论 How can I delete a Column of XLSX file with EPPlus in web app 它很安静,所以我只想检查是否有办法做到这一点。 或者,有没有办法将 epplus excel sheet 转换为 microsoft interop excel sheet 并执行一些操作。
目前,我有这样的代码:
for(int j=1; j <= 9; j++) //looping through columns
{
int flag = 0;
for(int i = 3; i <= 10; i++) // looping through rows
{
if(worksheet.cells[i, j].Text != "")
{
flag ++;
}
}
if (flag == 0)
{
worksheet.column[j].hidden = true; // hiding the columns- want to remove it
}
}
我们可以这样做吗:
Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
xlApp = worksheet; (where worksheet is epplus worksheet)
【问题讨论】: