working with Excel interop in C#.

// Create a new instance of the Excel application
excelFile = new Excel.ApplicationClass();
Excel.Workbook workbook = excelFile.sheet if neccessary

ws.Activate();

//Here is how to set the column Width

public void SetColumnWidth(Worksheet ws, int col, int width)
{
((Range)ws.Cells[1, col]).EntireColumn.ColumnWidth = width;
}

// Apply the setting so that it would autofit to contents
public void AutoFitColumn(Worksheet ws, int col)
{
((Range)ws.Cells[1, col]).EntireColumn.AutoFit();
}


How to Set Row to Bold in Excel C# Interop:

((Range)ws.Cells[row, 1]).EntireRow.Font.Bold = true;


How to Set a value inside a cell in Excel:

(Range)ws.Cells[row, column]).Value2 = item; // set the cell value at a row and column


How to Format the Entire Column:

((Range)ws.Cells[1, col]).EntireColumn.NumberFormat = format;

 

相关文章:

  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2021-11-13
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-29
  • 2021-11-13
  • 2021-10-19
  • 2021-09-05
  • 2021-11-19
相关资源
相似解决方案