如何识别Excel工作表中的隐藏列

时间:2018-05-09 15:22:28

标签: c# excel-interop

我正在使用Excel互操作,打开Excel文件并将数据写入Excel工作表。 excel表中有隐藏的列,并且它们将数据写入隐藏列。如何识别隐藏列而不是在隐藏列中写入数据?

con.Open();           
string query1 =  "SELECT fi.* FROM ****",
SqlDataAdapter da = new SqlDataAdapter(query1, con);
DataSet ds = new DataSet();
// load the data set
da.Fill(ds);
con.Close();
// loop through the data set and write data to excel 
for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
    for (int j = 0; j <= ds.Tables[0].Columns.Count - 1; j++)
    {
        String data = ds.Tables[0].Rows[i].ItemArray[j].ToString();
        mWSheet1.Cells[i + 3, j + 1] = data;
    }
}
mWorkBook.SaveAs(path, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value);

0 个答案:

没有答案