使用c sharp将excel列标题添加到单个标题中
本文关键字:标题 添加 单个 sharp excel 使用 | 更新日期: 2023-09-27 18:10:03
我试图添加一对新的列到excel文件。我可以很容易地添加列,但我不知道如何添加列标题到excel文件。究竟如何向新添加的列添加列标头呢?下面是我如何在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);
您可以像这样写入任何单元格(这里只是写入"header"作为一个例子):
// Type _ = Type.Missing;
wkSheet.Range["A1", _].Value2 = "Heading 1";
wkSheet.Range["B1", _].Value2 = "Heading 2";
wkSheet.Range["C1", _].Value2 = "Heading 3";