原創(chuàng)|使用教程|編輯:郝浩|2013-09-13 14:20:36.000|閱讀 3455 次
概述:使用DevExpress Document Server的第一步就是需要在Visual Studio中加載DevExpress Document Server。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
DevExpress Document Server是DevExpress最新發(fā)布的.Net文檔處理庫,用于全代碼操作文檔,所以完全沒有可視化的界面。要使用DevExpress Document Server的第一步就是需要在Visual Studio中加載DevExpress Document Server。
1、打開Visual Studio,然后通過選擇FILE-New-Project…,創(chuàng)建一個(gè)新的Windows Forms Application項(xiàng)目。
2、添加以下庫為引用: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。
3、其實(shí)集成步驟在上一部已經(jīng)完成了,接下來用個(gè)小例子為大家展示下簡單的功能。使用以下代碼
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");
4、運(yùn)行項(xiàng)目,下圖就是執(zhí)行了以上代碼后生成的文件。
1、創(chuàng)建新的Windows Forms Application項(xiàng)目。
2、添加以下庫為引用: DevExpress.Docs.v13.1.dll、DevExpress.Data.v13.1.dll、DevExpress.Office.v13.1.Core.dll、DevExpress.RichEdit.v13.1.Core.dll。
3、還是提供一個(gè)簡單的實(shí)例,創(chuàng)建一個(gè)包括以下代碼的方法:
using DevExpress.XtraRichEdit; using DevExpress.XtraRichEdit.API.Native; // ... string fileName = "RichEditDocumentServerTest.docx"; using (RichEditDocumentServer srv = new RichEditDocumentServer()) { Document doc = srv.Document; doc.AppendText("Document created by the RichEditDocumentServer."); CharacterProperties cp = doc.BeginUpdateCharacters(doc.Paragraphs[0].Range); cp.ForeColor = Color.Blue; doc.EndUpdateCharacters(cp); ParagraphProperties pp = doc.BeginUpdateParagraphs(doc.Paragraphs[0].Range); pp.Alignment = ParagraphAlignment.Right; doc.EndUpdateParagraphs(pp); srv.SaveDocument(fileName, DocumentFormat.OpenXml); } System.Diagnostics.Process.Start(fileName);
4、運(yùn)行該項(xiàng)目并執(zhí)行該方法,你會(huì)發(fā)現(xiàn)創(chuàng)建了一個(gè)叫RichEditDocumentServerTest.docx的文檔。
1、步驟一樣,不過添加引用只用添加DevExpress.Docs.v13.1.dll。
2、創(chuàng)建以下代碼的方法,生成了一個(gè)叫Test.zip的壓縮文件,密碼是123。
using DevExpress.Compression; // ... string zipFileName = "Test.zip"; string sourceDir = "C:\\Users\\Public\\Documents\\DXperience 13.1 Demos\\Data"; string password = "123"; EncryptionType encryptionType = EncryptionType.PkZip; using (ZipArchive archive = new ZipArchive()) { archive.Password = password; archive.EncryptionType = encryptionType; archive.AddDirectory(sourceDir); archive.Save(zipFileName); }
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)