using IronXL;
// Create new Excel WorkBook document
WorkBook workBook = WorkBook.Create();
// Convert XLSX to XLS
WorkBook xlsWorkBook = WorkBook.Create(ExcelFileFormat.XLS);
// Create a blank WorkSheet
WorkSheet workSheet = workBook.CreateWorkSheet("new_sheet");
// Add data and styles to the new worksheet
workSheet["A1"].Value = "Hello World";
workSheet["A1"].Style.WrapText = true;
workSheet["A2"].BoolValue = true;
workSheet["A2"].Style.BottomBorder.Type = IronXL.Styles.BorderType.Double;
// Save the excel file as XLS, XLSX, CSV, TSV, JSON, XML, HTML and streams
workBook.SaveAs("sample.xlsx");
Imports IronXL
' Create new Excel WorkBook document
Private workBook As WorkBook = WorkBook.Create()
' Convert XLSX to XLS
Private xlsWorkBook As WorkBook = WorkBook.Create(ExcelFileFormat.XLS)
' Create a blank WorkSheet
Private workSheet As WorkSheet = workBook.CreateWorkSheet("new_sheet")
' Add data and styles to the new worksheet
Private workSheet("A1").Value = "Hello World"
Private workSheet("A1").Style.WrapText = True
Private workSheet("A2").BoolValue = True
Private workSheet("A2").Style.BottomBorder.Type = IronXL.Styles.BorderType.Double
' Save the excel file as XLS, XLSX, CSV, TSV, JSON, XML, HTML and streams
workBook.SaveAs("sample.xlsx")
Install-Package IronXL.Excel
建立新的 Excel 文件
IronXL 庫可以用來從 XLS 和 XLSX 格式創建 Excel 文件。使用 IronXL 直觀的 API 來編輯和填充您的工作簿。通過 Value 屬性訪問單元格的值。單元格的樣式也可以使用 IronXL 更改。
以下的 Style 屬性都可以配置:
DiagonalBorder
Indention
Rotation
FillPattern
VerticalAlignment
HorizontalAlignment
DiagonalBorderDirection
WrapText
ShrinkToFit
TopBorder
RightBorder
LeftBorder
BackgroundColorFont
BottomBorder
SetBackgroundColor
請注意,對於 CSV、TSV、JSON 和 XML 文件格式,每個文件將對應於每個工作表創建。命名規則是 fileName.sheetName.format。在上面的例子中,CSV 格式的輸出將是 sample.new_sheet.csv。