Hello,
I tried the following code to copy the gridview to a Word Document and keep getting the error that the index is out of range. NOt sure what I am doing wrong, can someone please assist me.
Section s = document.AddSection();
Spire.Doc.Table table = s.AddTable(true);
//Create Header and Data
String[] Header = { "Task", "# Completed", "Event", "# Participants", "Counselor" };
String[][] data = new String[2][];
for (int k = 0; k < 2; k++)
{
data[k] = new string[GridView1.Columns.Count];
for (int j = 0; j < GridView1.Columns.Count; j++)
{
data[k][j] = GridView1.Rows[k].Cells[j].Text.ToString();
}
}
//Add Cells
table.ResetCells(data.Length + 1, Header.Length);
//Header Row
Spire.Doc.TableRow FRow = table.Rows[0];
FRow.IsHeader = true;
//Row Height
FRow.Height = 23;
//Header Format
FRow.RowFormat.BackColor = Color.AliceBlue;
for (int i = 0; i < Header.Length; i++)
{
//Cell Alignment
Paragraph p = FRow.Cells[i].AddParagraph();
FRow.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
p.Format.HorizontalAlignment = HorizontalAlignment.Center;
//Data Format
TextRange TR = p.AppendText(Header[i]);
TR.CharacterFormat.FontName = "Calibri";
TR.CharacterFormat.FontSize = 12;
TR.CharacterFormat.TextColor = Color.Teal;
TR.CharacterFormat.Bold = true;
}
//Data Row
for (int r = 0; r < data.Length; r++)
{
Spire.Doc.TableRow DataRow = table.Rows[r + 1];
//Row Height
DataRow.Height = 20;
//C Represents Column.
for (int c = 0; c < data[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(data[r][c]);
//Format Cells
p2.Format.HorizontalAlignment = HorizontalAlignment.Center;
TR2.CharacterFormat.FontName = "Calibri";
TR2.CharacterFormat.FontSize = 11;
TR2.CharacterFormat.TextColor = Color.Brown;
}
}