Spire.DOC生成表格測試


  首先,很感謝Jack對我的信任,讓我來寫一個評測,在此對Jack說一聲抱歉,由於本人愚鈍,並且最近項目比較緊張,把評測這個事情脫了一個月之久,由於往后的日子可能更忙,所以今晚抽空只能只寫了一個小程序來測試。

  Spire系列的Word,PDF,Excel,Presentation是一套專為.NET開發人員設計的控件。使用該套工具,程序員可以在任意.NET平台上對Office文件、PDF文檔進行生成,讀取,編輯,修改,轉換格式等處理,且不需要安裝MS Office

  紅字部分的內容,是有Jack給我發郵件的時候,里面的內容,最讓我心動的是最后一句話,不需要安裝MS Office,大家都知道,Office是很大的,如果不用Office是最好的。

但是在寫小例子的過程中,發現,需要有有一個DOC的模板共DLL打開,才能寫入內容,也就是說在沒有模板的情況下,是不可以的。從側面想一下,就是如果我的機器上只裝了WPS也是可以進行Word開發的(當然,這是我的假象,沒有實際測試。)

先看一下效果

  由於發給我的是測試版的DLL文件,所以在生成的Word上面會有“Evaluation Warning : The document was created with Spire.Doc for .NET.”紅字的提示,這個倒不是很重要,下面的表格,就是我用Spire.Doc.dll生成的。

  由於本人愚鈍,第一次創建項目時,沒有同時引用Spire.Doc和Spire.License兩個文件,所以導致工程出錯,給Jack添了不少麻煩。

  個人感覺相較於Office,Spire用起來還是很方便的,顯示表頭,只需要添加好的Header數組進行一個循環就可以,內容部分也差不多,就不寫了。

TableRow row = table.Rows[0];
 row.IsHeader = true;
 row.Height = 25f;
 for(int i=0;i<header.Length;i++)
 {
 row.Cells[i].CellFormat.VerticalAlignment = Spire.Doc.Documents.VerticalAlignment.Middle;
 Paragraph p = row.Cells[i].AddParagraph();
 p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
TextRange textRange = p.AppendText(header[i]);
textRange.CharacterFormat.Bold = true;
}
Header Code

  在保存Word的時候,可以直接調用Document下的一個保存方法SaveToFile

public void SaveToFile(string fileName, FileFormat fileFormat);

  個人認為方便的是FileFormat提供了一個文件格式的枚舉,可以讓開發者方便的選擇,當然,如果在提供前台選擇頁面的時候,也可以讓用戶來選擇

 public enum FileFormat
    {
        //
        // 摘要:
        //     Microsoft Word 97 - 2003 Binary Document.
        Doc,
        //
        // 摘要:
        //     Microsoft Word 97 - 2003 Binary Document or Template.
        Dot,
        //
        // 摘要:
        //     Microsoft Word 2007 Document.
        Docx,
        //
        // 摘要:
        //     Microsoft Word 2010 Document
        Docx2010,
        //
        // 摘要:
        //     Microsoft Word 2013 Document
        Docx2013,
        //
        // 摘要:
        //     Microsoft Word 2007 Template format.
        Dotx,
        //
        // 摘要:
        //     Microsoft Word 2010 Template format.
        Dotx2010,
        //
        // 摘要:
        //     Microsoft Word 2013 Template format.
        Dotx2013,
        //
        // 摘要:
        //     Microsoft Word 2007 macro enabled file format.
        Docm,
        //
        // 摘要:
        //     Microsoft Word 2010 macro enabled file format.
        Docm2010,
        //
        // 摘要:
        //     Microsoft Word 2013 macro enabled file format.
        Docm2013,
        //
        // 摘要:
        //     Microsoft Word 2007 macro enabled template format.
        Dotm,
        //
        // 摘要:
        //     Microsoft Word 2010 macro enabled template format.
        Dotm2010,
        //
        // 摘要:
        //     Microsoft Word 2013 macro enabled template format.
        Dotm2013,
        //
        // 摘要:
        //     PDF format
        PDF,
        //
        // 摘要:
        //     Rtf format
        Rtf,
        //
        // 摘要:
        //     Xml file format.
        Xml,
        //
        // 摘要:
        //     Text file format.
        Txt,
        //
        // 摘要:
        //     Html format.
        Html,
        //
        // 摘要:
        //     XPS format
        XPS,
        //
        // 摘要:
        //     EPub format
        EPub,
        //
        // 摘要:
        //     WordprocessingML format
        WordML,
        //
        // 摘要:
        //     Word xml format.
        WordXml,
        //
        // 摘要:
        //     The document is in the Word 6 or Word 95 format. Spire.Doc does not currently
        //     support loading such documents.
        DocPre97,
        //
        // 摘要:
        //     Instructs Spire.Doc to recognize the format automatically.
        Auto
    }

該睡覺了,就寫到這吧,實在抱歉了Jack,我的語言太拙劣了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM