0 голосов
спросил от в категории ASPNETC5
Попробуйте это,
создайте хорошо отформатированную HTML-строку, конвертируйте html в документ ms Word
0 ## ## [#^ #]

#https://weblogs.asp.net/dixin/convert-html-to-well-formatted-microsoft-word-document # [#^ #]

Пожалуйста, войдите или зарегистрируйтесь чтобы ответить на этот вопрос.

0 голосов
ответил от
try             {                 progressBar1.Visible = true;                                 Microsoft.Office.Interop.Word.Application winword = new Microsoft.Office.Interop.Word.Application();                 winword.Visible = false;                 //Create a missing variable for missing value                 object missing = System.Reflection.Missing.Value;                 //Create a new document                 Microsoft.Office.Interop.Word.Document document = winword.Documents.Add(ref missing, ref missing, ref missing, ref missing);                                               document.Content.SetRange(0, 0);                                 Microsoft.Office.Interop.Word.Paragraph para1 = document.Content.Paragraphs.Add(ref missing);                 object styleHeading1 = "Heading 1";                 para1.Range.set_Style(ref styleHeading1);                 para1.Range.Text = "Post Add report";                 para1.Range.InsertParagraphAfter();                 string samplePath2 = System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "IPIMages" + Path.DirectorySeparatorChar;                 string imagePath = samplePath2 + "logo.jpg";                 Paragraph para = document.Content.Paragraphs.Add(ref missing);                 para.Range.InsertParagraphBefore();                                 InlineShape map = document.InlineShapes.AddPicture(imagePath, ref missing, ref missing, ref missing);                 map.Height = 176;                 map.Width = 177;                 para.Range.InsertParagraphAfter();                 object oPageBreak = Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;                 para.Range.InsertBreak(ref oPageBreak);                 string[] coulmnname = value.Split(',');                 int coulmcount = dt.Rows.Count;                 progressBar1.Maximum = coulmcount-1;                 #region                  Table firstTable = document.Tables.Add(para1.Range, coulmcount - 1, 7, ref missing, ref missing);                 firstTable.Borders.Enable = 1;                 int i = 0, r = 0, s = 0; string img = "";                 string samplePath = "", imagepath = "";                 foreach (Row row in firstTable.Rows)                 {                     r++;                     int j = 0;                     foreach (Cell cell in row.Cells)                     {                         progressBar1.Value = r;                         //Header row                         if (cell.RowIndex == 1)                         {                             cell.Range.Text = coulmnname[i].ToString();                             cell.Range.Font.Bold = 1;                             cell.Range.Font.Name = "verdana";                             cell.Range.Font.Size = 10;                             cell.Shading.BackgroundPatternColor = WdColor.wdColorGray25;                             cell.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;                             cell.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;                             i++;                         }                         //Data row                         else                         {                             if (j == 3)                             {                                 img = dt.Rows[r - 2][coulmnname[j]].ToString();                                 if (img == "No image")                                 {                                     cell.Range.Text = dt.Rows[r - 2][coulmnname[j]].ToString();                                     cell.Range.Font.Name = "Century";                                     cell.Range.Font.Size = 14;                                     cell.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;                                     cell.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;                                     j++;                                 }                                 else                                 {                                     samplePath = System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "PostAd" + Path.DirectorySeparatorChar;                                     imagepath = samplePath + dt.Rows[r - 2][coulmnname[j]];                                     Range rngPic2 = document.Tables[1].Cell(r, 4).Range;                                     rngPic2.InlineShapes.AddPicture(imagepath, ref missing, ref missing, ref missing);                                     j++;                                 }                             }                             else if (j == 4)                             {                                 img = dt.Rows[r - 2][coulmnname[j]].ToString();                                 if (img == "No image")                                 {                                     cell.Range.Text = dt.Rows[r - 2][coulmnname[j]].ToString();                                     cell.Range.Font.Name = "Century";                                     cell.Range.Font.Size = 14;                                     cell.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;                                     cell.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;                                     j++;                                 }                                 else                                 {                                     samplePath = System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "PostAd" + Path.DirectorySeparatorChar;                                     imagepath = samplePath + dt.Rows[r - 2][coulmnname[j]];                                     Range rngPic2 = document.Tables[1].Cell(r, 5).Range;                                     rngPic2.InlineShapes.AddPicture(imagepath, ref missing, ref missing, ref missing);                                     j++;                                 }                             }                             else if (j == 5)                             {                                 img = dt.Rows[r - 2][coulmnname[j]].ToString();                                 if (img == "No image")                                 {                                     cell.Range.Text = dt.Rows[r - 2][coulmnname[j]].ToString();                                     cell.Range.Font.Name = "Century";                                     cell.Range.Font.Size = 14;                                     cell.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;                                     cell.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;                                     j++;                                 }                                 else                                 {                                     samplePath = System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "PostAd" + Path.DirectorySeparatorChar;                                     imagepath = samplePath + dt.Rows[r - 2][coulmnname[j]];                                     Range rngPic2 = document.Tables[1].Cell(r, 6).Ran

Категории

Добро пожаловать на сайт DraftingCode Q&A, где вы можете задавать вопросы и получать ответы от других членов сообщества.

Связанных вопросов не найдено

...