I am using Spire.Doc to export datagridview data to word, i am using below code, the problem is dont want to declare the array size it should be auto calculated as per the Rows of the Datagridview
Can anyone help me on the below where i can later add more than 1 Datagridview details also....
- using Spire.Doc;
- using Spire.Doc.Documents;
- using Spire.Doc.Fields;
- Document doc = new Document();
- Section section = doc.AddSection();
- Spire.Doc.Table table3 = section.AddTable(true);
- String[] Header3 = { "Column1", "Column2" };
- String[][] data3 = new String[4][];
- for (int k = 0; k < 4; k++)
- {
- data3[k] = new string[this.DataGridView.ColumnCount];
- for (int j = 0; j < this.DataGridView.ColumnCount; j++)
- {
- data3[k][j] = this.DataGridView.Rows[k].Cells[j].Value.ToString();
- }
- }
-
- table3.ResetCells(data3.Length + 1, Header3.Length);
- table3.TableFormat.Borders.Horizontal.LineWidth = 1;
- table3.TableFormat.Borders.Vertical.LineWidth = 1;
-
- Spire.Doc.TableRow FRow3 = table3.Rows[0];
- FRow3.IsHeader = true;
-
- FRow3.Height = 23;
- for (int i = 0; i < Header3.Length; i++)
- {
-
- Paragraph p1 = FRow3.Cells[i].AddParagraph();
- FRow3.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
- p1.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
-
- TextRange TR = p1.AppendText(Header3[i]);
- TR.CharacterFormat.FontName = "Century Gothic";
- TR.CharacterFormat.FontSize = 13;
-
- TR.CharacterFormat.Bold = true;
- }
-
- for (int r = 0; r < data3.Length; r++)
- {
- Spire.Doc.TableRow DataRow = table3.Rows[r + 1];
-
- DataRow.Height = 20;
-
- for (int c = 0; c < data3[r].Length; c++)
- {
-
- DataRow.Cells[c].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
-
- Paragraph p2 = DataRow.Cells[c].AddParagraph();
- TextRange TR2 = p2.AppendText(data3[r][c]);
-
- p2.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
- TR2.CharacterFormat.FontName = "Century Gothic";
- TR2.CharacterFormat.FontSize = 12;
-
- }
- }
- doc.SaveToFile("OperateWord.docx", FileFormat.Docx);
- System.Diagnostics.Process.Start("OperateWord.docx");