原創(chuàng)|使用教程|編輯:何躍|2021-12-14 13:28:57.950|閱讀 570 次
概述:Free Spire.office 完全免費并沒有任何警告信息,但是免費版有對操作的 Word, Excel, PowerPoint 和 PDF 文檔有篇幅限制。 如果您的文檔超出了我們的篇幅使用限制,請使用我們的 Spire.office 商業(yè)版本。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
看到WPS給鼠標(biāo)右鍵加了3個相關(guān)功能,正好這段時間在熟悉相關(guān)開發(fā),今天就用Spire.Doc for .NET寫個簡單的程序??
這一步你可以按照上圖去布局調(diào)整,甚至加入其他功能等,比如水印的角度等。
點擊這里下載免費的類庫,F(xiàn)ree Spire.office 完全免費并沒有任何警告信息,但是免費版有對操作的 Word, Excel, PowerPoint 和 PDF 文檔有篇幅限制。 如果您的文檔超出了我們的篇幅使用限制,請使用我們的 Spire.office 商業(yè)版本。
1. 批量加入Doc文件
OpenFileDialog odf = new OpenFileDialog(); odf.Multiselect = true; odf.RestoreDirectory = true; odf.Title = "打開你所選取的文件"; odf.Filter = "Word文檔|*.doc;*.docx"; if (odf.ShowDialog() == DialogResult.OK) { if (odf.FileNames.Length == 0) { MessageBox.Show("您未選擇任何文件"); return; } for (int i = 0; i < odf.FileNames.Length; i++) { dgv.Rows.Add(odf.SafeFileNames[i], odf.FileNames[i]); } }
2. 實現(xiàn)輸出事件
if (dgv.Rows.Count == 0) { MessageBox.Show("您還沒有選擇文件"); return; } // 1. 添加水印 // 2. 添加密碼 // 3. 轉(zhuǎn)換PDF文件 foreach (DataGridViewRow R in dgv.Rows) { string filepath = R.Cells[1].Value.ToString().Trim(); //把word加載 Document document = new Document(filepath); //新增水印 InsertTextWatermark(document.Sections[0]); Section section = document.Sections[0]; //新增頁眉頁腳 InsertHeaderAndFooter(section); //保存一個Word看效果,如果不需要請注釋掉 document.SaveToFile(saveDir + "Sample.docx", FileFormat.Docx); //實例化一個PDF的參數(shù)設(shè)置 ToPdfParameterList toPdf = new ToPdfParameterList(); //設(shè)置密碼 string password = textBox2.Text.Trim(); toPdf.PdfSecurity.Encrypt(password, password, Spire.Pdf.Security.PdfPermissionsFlags.Default, Spire.Pdf.Security.PdfEncryptionKeySize.Key128Bit); //保存 document.SaveToFile(saveDir + "EncryptWithPassword.pdf", toPdf); //打開效果測試 System.Diagnostics.Process.Start(saveDir + "EncryptWithPassword.pdf");
private void InsertTextWatermark(Section section)//添加水印功能 { TextWatermark txtWatermark = new TextWatermark(); txtWatermark.Text = textBox1.Text; txtWatermark.FontSize = 95; txtWatermark.Color = Color.Blue; txtWatermark.Layout = WatermarkLayout.Diagonal; section.Document.Watermark = txtWatermark; }
以上功能實現(xiàn)代碼都可以從冰藍的樣例中心獲取,不過業(yè)務(wù)邏輯得按照你的自己需求調(diào)整。
E-iceblue功能類庫Spire 系列文檔處理組件均由中國本土團隊研發(fā),不依賴第三方軟件,不受其他國家的技術(shù)或法律法規(guī)限制,同時適配國產(chǎn)操作系統(tǒng)如中科方德、中標(biāo)麒麟等,兼容國產(chǎn)文檔處理軟件 WPS(如 .wps/.et/.dps 等格式),具體的開發(fā)需要具體的類庫,點擊這里下載全部。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn