原創|使用教程|編輯:龔雪|2015-12-09 17:11:28.000|閱讀 2994 次
概述:表格控件Aspose.Cells支持所有Excel格式類型的操作,在沒有Microsoft Excel的環境下,用戶也可為其應用程序嵌入類似Excel的強大數據管理功能。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
下面就是使用Aspose.Cells API創建Hello World應用程序的步驟:
以上步驟的實現在下面的例子中的展示:
代碼示例:創建一個新的Workbook
下面的例子展示了從零開始創建一個新的Workbook,把 Hello World!寫入到第一個工作表的A1單元格,并保存為Excel文件。
輸出電子表格
C#
//Create a License object License license = new License(); //Set the license of Aspose.Cells to avoid the evaluation //limitations license.SetLicense("Aspose.Cells.lic"); //Instantiate a Workbook object that represents Excel file. Workbook wb = new Workbook(); //Note when you create a new workbook, a default worksheet //"Sheet1" is added (by default) to the workbook. //Access the first worksheet "Sheet1" in the book. 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("d:\\MyBook.xls", SaveFormat.Excel97To2003);
VB.NET
'Create a License object Dim license As License = New License() 'Set the license of Aspose.Cells to avoid the evaluation 'limitations license.SetLicense("Aspose.Cells.lic") 'Instantiate a Workbook object that represents Excel file. Dim wb As Workbook = New Workbook() 'Note when you create a new workbook, a default worksheet '"Sheet1" is added (by default) to the workbook. 'Access the first worksheet "Sheet1" in the book. Dim sheet As Worksheet = wb.Worksheets(0) 'Access the "A1" cell in the sheet. Dim cell As Cell = sheet.Cells("A1") 'Input the "Hello World!" text into the "A1" cell cell.PutValue("Hello World!") 'Save the Excel file. wb.Save("d:\MyBook.xls", SaveFormat.Excel97To2003)
代碼示例:打開一個現有文件
下面的例子展示了打開一個名為“book.xls”的Microsoft Excel模板文件,并輸入“Hello World”文本到第一個工作表的A1單元格中,最后保存為workbook。
C#
//Create a License object License license = new License(); //Set the license of Aspose.Cells to avoid the evaluation limitations license.SetLicense("Aspose.Cells.lic"); //Creating a file stream containing the Excel file to be opened FileStream fstream = new FileStream("C:\\book1.xls", FileMode.Open); //Instantiate a Workbook object that represents the existing Excel file Workbook workbook = new Workbook(fstream); //Get the reference of "A1" cell from the cells collection of a worksheet Cell cell = workbook.Worksheets[0].Cells["A1"]; //Put the "Hello World!" text into the "A1" cell cell.PutValue("Hello World!"); //Save the Excel file workbook.Save("C:\\HelloWorld.xls"); //Closing the file stream to free all resources fstream.Close();
VB.NET
'Create a License object Dim license As License = New License() 'Set the license of Aspose.Cells to avoid the evaluation limitations license.SetLicense("Aspose.Cells.lic") 'Creating a file stream containing the Excel file to be opened Dim fstream As FileStream = New FileStream("C:\book1.xls", FileMode.Open) 'Instantiate a Workbook object that represents the existing Excel file Dim workbook As Workbook = New Workbook(fstream) 'Get the reference of "A1" cell from the cells collection of a worksheet Dim cell As Cell = workbook.Worksheets(0).Cells("A1") 'Put the "Hello World!" text into the "A1" cell cell.PutValue("Hello World!") 'Save the Excel file workbook.Save("C:\HelloWorld.xls") 'Closing the file stream to free all resources fstream.Close()
購買最新正版授權!""
慧都年終盛典火爆開啟,一年僅一次的最強促銷,破冰鉅惠不容錯過??!優惠詳情點擊查看>>
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn