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();
- }
- }
- //Add Cells
- table3.ResetCells(data3.Length + 1, Header3.Length);
- table3.TableFormat.Borders.Horizontal.LineWidth = 1;
- table3.TableFormat.Borders.Vertical.LineWidth = 1;
- //Header Row
- Spire.Doc.TableRow FRow3 = table3.Rows[0];
- FRow3.IsHeader = true;
- //Row Height
- FRow3.Height = 23;
- for (int i = 0; i < Header3.Length; i++)
- {
- //Cell Alignment
- Paragraph p1 = FRow3.Cells[i].AddParagraph();
- FRow3.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
- p1.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
- //Data Format
- TextRange TR = p1.AppendText(Header3[i]);
- TR.CharacterFormat.FontName = "Century Gothic";
- TR.CharacterFormat.FontSize = 13;
- //TR.CharacterFormat.TextColor = Color.Teal;
- TR.CharacterFormat.Bold = true;
- }
- //Data Row
- for (int r = 0; r < data3.Length; r++)
- {
- Spire.Doc.TableRow DataRow = table3.Rows[r + 1];
- //Row Height
- DataRow.Height = 20;
- //C Represents Column.
- for (int c = 0; c < data3[r].Length; c++)
- {
- //Cell Alignment
- DataRow.Cells[c].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
- //Fill Data in Rows
- Paragraph p2 = DataRow.Cells[c].AddParagraph();
- TextRange TR2 = p2.AppendText(data3[r][c]);
- //Format Cells
- p2.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
- TR2.CharacterFormat.FontName = "Century Gothic";
- TR2.CharacterFormat.FontSize = 12;
- //TR2.CharacterFormat.TextColor = Color.Brown;
- }
- }
- doc.SaveToFile("OperateWord.docx", FileFormat.Docx);
- System.Diagnostics.Process.Start("OperateWord.docx");
Manish ParmarPosted Jun 15, 2020, 12:40 PM
Leon DPosted Jun 14, 2020, 9:48 PM