可能很容易。我怎樣才能改變行或列高?以編程方式更改excel行或列的高度
xlApp = new Excel.Application();
xlApp.Visible = true;
xlApp.DisplayAlerts = false;
Excel.Workbooks xlWorkBooks = xlApp.Workbooks;
xlWorkBook = xlWorkBooks.Open(directoryPath + "\\" + fileName, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
xlWorkSheets = xlWorkBook.Worksheets; //Get all the sheets in the workbook
xlWorkSheet = (Excel.Worksheet)xlWorkSheets.get_Item("Sheet1"); //Get the allready exists sheet
Excel.Range range = xlWorkSheet.UsedRange;
Excel.Range chartRange;
int colCount = range.Columns.Count;
int rowCount = range.Rows.Count;
xlWorkSheet.Cells[rowCount + 5, 1] = "Name and surname";
chartRange = xlWorkSheet.get_Range("a" + (rowCount + 5), "e" + (rowCount + 5));
chartRange.Font.Bold = true;
xlWorkBook.SaveAs(fileName, Excel.XlFileFormat.xlOpenXMLWorkbook, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(misValue, misValue, misValue);
xlWorkSheet = null;
xlWorkBook = null;
xlApp.Quit();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
與xlWorkSheet.UsedRange.EntireRow.Height = value;
一起嘗試,但它不起作用。 autoFit()
正在工作,但我想與我的價值工作。
你有沒有嘗試使用'OfficeOpenXml'?這很容易,你可以做到這一點。如果你想,我可以粘貼一些代碼,看看它是什麼樣子:) – Bip 2012-03-29 09:42:06
請做。如此簡單的功能,所以很難找到。 – JanOlMajti 2012-03-29 09:47:45
'xlsgen'可能類似於你的'OfficeOpenXml' http://xlsgen.arstdesign.com/core/rowsandcolumns.html – JanOlMajti 2012-03-29 09:57:56