在VS中添加DevExpress Document Server
如何在Visual Studio中添加无界面的.Net文档处理库DevExpress Document Server在中的电子表格服务器。
操作方法
- 01
打开Visual Studio,然后通过选择FILE-New-Project…,创建一个新的Windows Forms Application项目。
- 02
添加以下库为引用:DevExpress.Data.v13.1.dll、 DevExpress.Docs.v13.1.dll、 DevExpress.Office.v13.1.Core.dll、 DevExpress.Spreadsheet.v13.1.Core.dll和DevExpress.Utils.v13.1.dll。
- 03
其实集成步骤在上一部已经完成了,接下来用个小例子为大家展示下简单的功能。使用以下代码: using DevExpress.Spreadsheet; // ... // Create an instance of a workbook. Workbook workbook = new DevExpress.Spreadsheet.Workbook(); // Access the first worksheet in the workbook. Worksheet worksheet = workbook.Worksheets[0]; // Access the "A1" cell in the worksheet. Cell cell = worksheet.Cells["A1"]; // Specify the "A1" cell value. cell.Value = 1; // Fill cells with sequential numbers by using shared formulas. worksheet.Range["A2:A10"].Formula = "=SUM(A1+1)"; worksheet.Range["B1:B10"].Formula = "=A1+2"; // Multiply values contained in the cell range A1 through A10 // by the corresponding values contained in B1 through B10, // and display the results in cells C1 through C10. worksheet.Cells["C1"].CreateArrayFormula("=A1:A10*B1:B10", 10, 1); // Save the document file under the specified name. workbook.SaveDocument("TestDoc.xlsx", DocumentFormat.OpenXml); // Display gridlines in PDF. worksheet.PrintOptions.PrintGridlines = true; // Export the document to PDF. workbook.ExportToPdf("TestDoc.pdf"); // Open the PDF document using the default viewer.. System.Diagnostics.Process.Start("TestDoc.pdf"); // Open the XLSX document using the default application. System.Diagnostics.Process.Start("TestDoc.xlsx");
- 04
运行项目,下图就是执行了以上代码后生成的文件。