我正在尝试将一些新列添加到excel文件中。我可以很容易地添加列,但我无法弄清楚如何将列标题添加到excel文件。如何在新添加的列中添加列标题?以下是我如何在An Excel工作表中添加3个新列。
Range rng = (Range)wkSheet.get_Range("A1", Type.Missing);
rng.EntireColumn.Insert(XlInsertShiftDirection.xlShiftToRight,
XlInsertFormatOrigin.xlFormatFromRightOrBelow);
Range rng2 = (Range)wkSheet.get_Range("A1", Type.Missing);
rng2.EntireColumn.Insert(XlInsertShiftDirection.xlShiftToRight,
XlInsertFormatOrigin.xlFormatFromRightOrBelow);
Range rng3 = (Range)wkSheet.get_Range("A1", Type.Missing);
rng3.EntireColumn.Insert(XlInsertShiftDirection.xlShiftToRight,
XlInsertFormatOrigin.xlFormatFromRightOrBelow);
wkSheet.SaveAs("C:\\Code\\UPMC\\ISD\\EADIS\\UPMC.ISD.EADIS.ACO.ACOBackLoad\\App_Data\\test", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
答案 0 :(得分:1)
您可以像这样写入任何单元格(这只是写入“标题”作为示例):
// Type _ = Type.Missing;
wkSheet.Range["A1", _].Value2 = "Heading 1";
wkSheet.Range["B1", _].Value2 = "Heading 2";
wkSheet.Range["C1", _].Value2 = "Heading 3";