I am attempting to add a couple of new columns to an excel file. I can add the column pretty easily, but I can't figure out how to add a column header to the excel file. How on earth do you add a column header to a newly added column? Here is how I add 3 new columns to a An excel worksheet.
Range rng = (Range)wkSheet.get_Range("A1", Type.M开发者_如何学Pythonissing);
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);
You can write to any cell like so (this just writes to the "header" as an example):
// Type _ = Type.Missing;
wkSheet.Range["A1", _].Value2 = "Heading 1";
wkSheet.Range["B1", _].Value2 = "Heading 2";
wkSheet.Range["C1", _].Value2 = "Heading 3";
精彩评论