Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically alter an excel rows or columns heigh

Tags:

c#

excel

winforms

Probably easy one. How can i change rows or column heigh?

 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();

Try it with xlWorkSheet.UsedRange.EntireRow.Height = value; but it doesn't work. autoFit() is working but i would like to work with my value.

like image 442
JanOlMajti Avatar asked Sep 16 '26 01:09

JanOlMajti


1 Answers

I think you may be looking for RowHeight...

http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.namedrange.rowheight(v=vs.80).aspx

like image 77
paul Avatar answered Sep 17 '26 15:09

paul