1

i would to create in my c# project a file word from two different grid (in the same moment) but change font (size, bold ecc). for example i want to start with a title with bold 1 and Font.Size 12 then insert all rows from first grid with another size and without bold then insert a new text with bold 1 and Font.Size 12 and then copy all rows from second grid withanother size and without bold. then save and close without remaining append microsoft word process i'm trying using Microsoft.Office.Interop.Word.Application but i'm not able to change font, size ecc and process remain active. this is my code`

object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(ref oMissing);

doc = app.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
doc.Content.Font.Size = 12;
doc.Content.Font.Bold = 1;

doc.Content.Text += string.Format("Title of {0}",dteData.EditValue); 


doc = app.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
doc.Content.Font.Size = 8;
doc.Content.Font.Bold = 0;

for (int i = 0; i < gridViewMatt.RowCount; i++)
{
    DataRow row = gridViewMatt.GetDataRow(i);
    string name = row["NOME"].ToString();
    string nameServ = row["NOME_SERVIZIO"].ToString();

    doc.Content.Text += string.Format("{0} : {1}", name, nameServ);
}

// here second title with bold1 and then second grid .....

object pres = @"D:\\Presenze2.docx";
doc.SaveAs2(ref pres);
doc.Close();

thanks a lot

Kit
  • 20,354
  • 4
  • 60
  • 103
giovanna zoppi
  • 69
  • 1
  • 11
  • Does this answer your question? [how to change font size of word document using .net](https://stackoverflow.com/questions/29187587/how-to-change-font-size-of-word-document-using-net) – Mauricio Gracia Gutierrez Jun 21 '21 at 14:44
  • Consider using built-in Word features such as Table Styles and Quick Tables. Consider using a Word template that already has this in it rather than building through code. – Charles Kenyon Jun 21 '21 at 16:17

0 Answers0