加载和管理Excel、OpenOffice、Json、Csv和Html文件
Contents
[
Hide
]
使用Aspose.Cells,很容易创建、打开和管理Excel文件,例如检索数据或使用设计模板加快开发过程。
创建新工作簿
以下示例从头开始创建一个新工作簿。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
try | |
{ | |
// Create a License object | |
License license = new License(); | |
// Set the license of Aspose.Cells to avoid the evaluation limitations | |
license.SetLicense(dataDir + "Aspose.Cells.lic"); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
// Instantiate a Workbook object that represents Excel file. | |
Workbook wb = new Workbook(); | |
// When you create a new workbook, a default "Sheet1" is added to the workbook. | |
Worksheet sheet = wb.Worksheets[0]; | |
// Access the "A1" cell in the sheet. | |
Cell cell = sheet.Cells["A1"]; | |
// Input the "Hello World!" text into the "A1" cell | |
cell.PutValue("Hello World!"); | |
// Save the Excel file. | |
wb.Save(dataDir + "MyBook_out.xlsx"); |
打开和保存文件
使用Aspose.Cells,很容易打开、保存和管理Excel文件。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Opening through Path | |
// Creating a Workbook object and opening an Excel file using its file path | |
Workbook workbook1 = new Workbook(dataDir + "Book1.xlsx"); | |
//Adding new sheet | |
Worksheet sheet = workbook1.Worksheets.Add("MySheet"); | |
//Setting active aheet | |
workbook1.Worksheets.ActiveSheetIndex = 1; | |
//Setting values. | |
Cells cells = sheet.Cells; | |
//Setting text | |
cells["A1"].PutValue("Hello!"); | |
//Setting number | |
cells["A2"].PutValue(1000); | |
//Setting Date Time | |
Cell cell = cells["A3"]; | |
cell.Value = DateTime.Now; | |
Style style = cell.GetStyle(); | |
style.Number = 14; | |
cell.SetStyle(style); | |
//Setting formula | |
cells["A4"].Formula = "=SUM(A1:A3)"; | |
//Saving the workbook to disk. | |
workbook1.Save(dir + "dest.xlsx"); |
高级主题
- 打开文件的不同方式
- 在加载工作簿时过滤定义名称
- 在加载工作簿或工作表时筛选对象
- 从模板文件加载工作簿时筛选数据类型
- 加载 Excel 文件时获取警告
- 在不包含图表的源Excel文件中加载
- 加载工作簿中特定的工作表
- 加载带有指定打印纸张大小的工作簿
- 打开不同版本的Microsoft Excel文件
- 打开具有不同格式的文件
- 在处理具有大数据集的大文件时优化内存使用
- 使用 Aspose.Cells 读取由 Apple Inc. 开发的 Numbers 电子表格
- 在转换或加载花费太长时间时使用InterruptMonitor停止转换或加载
- 使用LightCells API
- 将CSV转换为JSON
- 将Excel转换为JSON
- 将JSON转换为CSV
- 将JSON转换为Excel
- 将Excel转换为Html