0
將顏色添加到Excel工作表中的單元格我正在使用C#COM Interop來即時創建和更新Excel文件。我使用了下面的代碼。但我不確定如何爲特定的單元添加顏色。請幫助我一樣。如何使用C#COM Interop
using Excel = Microsoft.Office.Interop.Excel;
Excel.Application excel = new Excel.Application();
excel.Visible = true;
Excel.Workbook wb = excel.Workbooks.Open(excel_filename);
Excel.Worksheet sh = wb.Sheets.Add();
sh.Name = "TestSheet";
sh.Cells[1, "A"].Value2 = "SNO";
sh.Cells[2, "B"].Value2 = "A";
sh.Cells[2, "C"].Value2 = "1122";
wb.Close(true);
excel.Quit();
感謝您的快速回復。你也可以讓我知道如何看到.Interior.Color屬性因爲當我檢查時,這些屬性是運行時。還可以讓我知道如何將寬度添加到單元格或適合傳遞給單元格的字符串。謝謝。 – Bhavani
Range.Rows.AutoFit(); Range.Columns.AutoFit(); – Mir
請點擊此鏈接http://www.spreadsheetgear.com/support/help/spreadsheetgear.net.3.0/SpreadsheetGear~SpreadsheetGear.IRange~AutoFit.html或http://csharp.net-informations.com/excel/csharp-格式excel.htm – Mir