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

2019-12-26 13:37:47王旭
  • oTable = oDoc.Tables.Add(wrdRng, 5, 2, ref oMissing, ref oMissing);  oTable.Range.ParagraphFormat.SpaceAfter = 6; 
  • for (r = 1; r <= 5; r++)  for (c = 1; c <= 2; c++) 
  • {  strText = "r" + r + "c" + c; 
  • oTable.Cell(r, c).Range.Text = strText;  } 
  • oTable.Columns[1].Width = oWord.InchesToPoints(2); //Change width of columns 1 & 2  oTable.Columns[2].Width = oWord.InchesToPoints(3); 
  • //Keep inserting text. When you get to 7 inches from top of the  //document, insert a hard page break. 
  • object oPos;  double dPos = oWord.InchesToPoints(7); 
  • oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range.InsertParagraphAfter();  do 
  • {  wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; 
  • wrdRng.ParagraphFormat.SpaceAfter = 6;  wrdRng.InsertAfter("A line of text"); 
  • wrdRng.InsertParagraphAfter();  oPos = wrdRng.get_Information 
  • (Word.WdInformation.wdVerticalPositionRelativeToPage);  } 
  • while (dPos >= Convert.ToDouble(oPos));  object oCollapseEnd = Word.WdCollapseDirection.wdCollapseEnd; 
  • object oPageBreak = Word.WdBreakType.wdPageBreak;  wrdRng.Collapse(ref oCollapseEnd); 
  • wrdRng.InsertBreak(ref oPageBreak);  wrdRng.Collapse(ref oCollapseEnd); 
  • wrdRng.InsertAfter("We're now on page 2. Here's my chart:");  wrdRng.InsertParagraphAfter(); 
  • //Insert a chart.  Word.InlineShape oShape; 
  • object oClassType = "MSGraph.Chart.8";  wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; 
  • oShape = wrdRng.InlineShapes.AddOLEObject(ref oClassType, ref oMissing,  ref oMissing, ref oMissing, ref oMissing, 
  • ref oMissing, ref oMissing, ref oMissing);  //Demonstrate use of late bound oChart and oChartApp objects to