C#实现HTML转WORD及WORD转PDF的方法

2019-12-26 13:37:47王旭
  • //manipulate the chart object with MSGraph.  object oChart; 
  • object oChartApp;  oChart = oShape.OLEFormat.Object; 
  • oChartApp = oChart.GetType().InvokeMember("Application",  BindingFlags.GetProperty, null, oChart, null); 
  • //Change the chart type to Line.  object[] Parameters = new Object[1]; 
  • Parameters[0] = 4; //xlLine = 4  oChart.GetType().InvokeMember("ChartType", BindingFlags.SetProperty, 
  • null, oChart, Parameters);  //Update the chart image and quit MSGraph. 
  • oChartApp.GetType().InvokeMember("Update",  BindingFlags.InvokeMethod, null, oChartApp, null); 
  • oChartApp.GetType().InvokeMember("Quit",  BindingFlags.InvokeMethod, null, oChartApp, null); 
  • //... If desired, you can proceed from here using the Microsoft Graph   //Object model on the oChart and oChartApp objects to make additional 
  • //changes to the chart.  //Set the width of the chart. 
  • oShape.Width = oWord.InchesToPoints(6.25f);  oShape.Height = oWord.InchesToPoints(3.57f); 
  • //Add text after the chart.  wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; 
  • wrdRng.InsertParagraphAfter();  wrdRng.InsertAfter("THE END."); 
  • //Close this form.  this.Close(); 
  • }  private void button2_Click(object sender, EventArgs e) 
  • {  string s = ""; 
  • if (openFileDialog1.ShowDialog() == DialogResult.OK)  { 
  • s = openFileDialog1.FileName;  } 
  • else  { 
  • return;  } 
  • // 在此处放置用户代码以初始化页面  Word.ApplicationClass word = new Word.ApplicationClass(); 
  • Type wordType = word.GetType();  Word.Documents docs = word.Documents; 
  • // 打开文件  Type docsType = docs.GetType(); 
  • object fileName = s;  Word.Document doc = (Word.Document)docsType.InvokeMember("Open",