Score
0
Watch 25 Star 104 Fork 12

Gitee星球的小活动 / 第 0 届 代码编故事接力赛

Join us
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
让我们点燃程序员写作之魂,一人用代码写一段故事玩玩吧~ spread retract

Clone or download
c# 驱动word的宏.cs 2.15 KB
Copy Edit Web IDE Raw Blame History
郑永生 authored 2020-03-24 18:13 . add c# 驱动word的宏.cs.
WinWord.Application oApp = new WinWord.Application();
oApp.Visible = true;
if (System.IO.File.Exists(@"D:\Demo\Test_Demo.pdf")) System.IO.File.Delete(@"D:\Demo\Test_Demo.pdf");
if (System.IO.File.Exists(@"D:\Demo\Test_Demo.docx")) System.IO.File.Delete(@"D:\Demo\Test_Demo.docx");
System.IO.File.Copy(@"D:\Demo\Test.docx", @"D:\Demo\Test_Demo.docx");
WinWord.Document oDoc = oApp.Documents.Open(@"D:\Demo\Test_Demo.docx", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
VB.VBComponent oModule = oDoc.VBProject.VBComponents.Add(VB.vbext_ComponentType.vbext_ct_StdModule);
string sCode = System.IO.File.ReadAllText("Script.vba");//读取脚本
Console.Write(sCode);
oModule.CodeModule.AddFromString(sCode);
oApp.Run("MK");
//oDoc.SaveAs2(@"D:\Demo\Test_Demo.pdf", WinWord.WdExportFormat.wdExportFormatPDF);
oDoc.ExportAsFixedFormat(@"D:\Demo\Test_Demo.pdf", WinWord.WdExportFormat.wdExportFormatPDF, true, WinWord.WdExportOptimizeFor.wdExportOptimizeForPrint, WinWord.WdExportRange.wdExportAllDocument, 0, 0, WinWord.WdExportItem.wdExportDocumentContent, true, true, WinWord.WdExportCreateBookmarks.wdExportCreateWordBookmarks);
//ObjExcelWorkBook.ExportAsFixedFormat(
// Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF,
// Environment.CurrentDirectory + @"\temp\" + 编辑页面.ToString() + 文件类型,
// Microsoft.Office.Interop.Excel.XlFixedFormatQuality.xlQualityStandard, Type.Missing, false, Type.Missing, Type.Missing, false, Type.Missing);
//oApp.GetType().InvokeMember("Run", System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.InvokeMethod, null, oApp, new object[] { "M1" });//运行已有脚本
oDoc.Close(Type.Missing,Type.Missing,Type.Missing);
oApp.Quit();
GC.Collect();//CleanMemery

Comment ( 0 )

Sign in for post a comment

1
https://gitee.com/Selected-Activities/Code-relay.git
git@gitee.com:Selected-Activities/Code-relay.git
Selected-Activities
Code-relay
第 0 届 代码编故事接力赛
master

Help Search

220309 7019f5b6 1899542 220318 4015cbb9 1899542