本帖最后由 冰岛 于 2023-6-1 16:38 编辑
谢谢版主的DEMO,起了很大作用。
再请问版主:当我设置了一次数据源之后,想添加第二个数据时会报错(即点下btnAddData_Click第二次)。代码如下。应该怎么处理呢?
private void btnAddData_Click(object sender, EventArgs e)
{
if (fpSpread1.AsWorkbook().ActiveSheet.Tables.Count <= 0)
{
GrapeCity.Spreadsheet.IWorksheet TestActiveSheet = fpSpread1.AsWorkbook().ActiveSheet;
TestActiveSheet.AutoFilterMode = false;
GrapeCity.Spreadsheet.ITable table = TestActiveSheet.Range("A1:G2").CreateTable(true);
table.ShowAutoFilter = false;
table.AutoGenerateColumns = true;
table.DataSource = dt;
fpSpread1.ActiveSheet.Rows[0, dt.Rows.Count].Visible = true;
}
else
{
int RowsCount = 0;
for (var i = 0; i < fpSpread1.AsWorkbook().ActiveSheet.Tables.Count; i++)
{
var dt = fpSpread1.AsWorkbook().ActiveSheet.Tables;
RowsCount += dt.TableRows.Count;
}
RowsCount += fpSpread1.AsWorkbook().ActiveSheet.Tables.Count;
string nRange = "A" + (RowsCount + 1) + ":G" + (RowsCount + 1);
GrapeCity.Spreadsheet.IWorksheet TestActiveSheet = fpSpread1.AsWorkbook().ActiveSheet;
GrapeCity.Spreadsheet.ITable table = TestActiveSheet.Range(nRange).CreateTable(true);
//table.ShowAutoFilter = false;
//table.AutoGenerateColumns = true;
table.DataSource = dt2;
fpSpread1.ActiveSheet.Rows[0, RowsCount + dt2.Rows.Count - 1].Visible = true;
}
}
|