[英]How to change the Worksheet name in Excel?
我想使用自定義名稱表將一些數據導出到Excel。
如何從C#更改工作表名稱?
這是我的代碼:
var workbook = new HSSFWorkbook();
var font = workbook.CreateFont();
font.Boldweight = HSSFFont.BOLDWEIGHT_BOLD;
sheet.SetColumnWidth(0, 10 * 256);
sheet.SetColumnWidth(1, 30 * 256);
headerRow.CreateCell(0).SetCellValue("Column1");
headerRow.CreateCell(1).SetCellValue("Column2");
int rowNumber = 1;
//Populate the sheet with values from the grid data
foreach (var m in model)
{
//Create a new row
var row = sheet.CreateRow(rowNumber++);
//Set values for the cells
row.CreateCell(0).SetCellValue(m.Column1);
row.CreateCell(1).SetCellValue(m.Column2);
}
Workbook workbook = new HSSFWorkbook();
Worksheet sheet = (Worksheet)workbook.Worksheets[index];
// you can also use the current worksheet name here
要更改名稱,您必須寫
sheet.Name = "TheNewWorksheetName";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.