And this problem?
I send the following code and I send the template.
I’ve been running some tests and found that if I remove the reference to datasource p in the template, it doesn’t throw an error. If I keep the datasource p, it throws the error: System.ArgumentException: ‘The ‘CodEstado’ column doesn’t belong to the table.’
private string ConnectionString()
{
System.Data.SqlClient.SqlConnectionStringBuilder builder =
new System.Data.SqlClient.SqlConnectionStringBuilder();
builder[“Data Source”] = @“alg4\sql2017”;
builder[“Initial Catalog”] = “MT205_2”;
builder[“Persist Security Info”] = false;
builder[“Password”] = “”;
builder[“User”] = “sa”;
builder[“Application Name”] = “Analogon.Excel”;
return builder.ConnectionString;
}
private System.Data.DataTable GetDataTable(System.Data.SqlClient.SqlConnection pCon, string pSQL)
{
System.Data.DataTable dt;
using (System.Data.SqlClient.SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter(pSQL, pCon))
{
dt = new System.Data.DataTable();
adapter.Fill(dt);
}
return dt;
}
private void button3_Click(object sender, EventArgs e)
{
GrapeCity.Documents.Excel.Workbook.SetLicenseKey(LicenseKey);
var workbook = new GrapeCity.Documents.Excel.Workbook();
workbook.Open(@"C:\Lab\GRA\GRA209\reports\xLstAPAGuia02_t.xlsx");
IWorkbook wb;
using (var con = new System.Data.SqlClient.SqlConnection(ConnectionString()))
{
con.Open();
var dt = GetDataTable(con, "SELECT QuantidadeAtual=(CASE WHEN quantidadeCrr=0 THEN Quantidade ELSE quantidadeCrr END),isNull(codigoOperacaoCrr,codigoOperacao) CodigoOperacaoAtual,isNull(codigoResiduoLerCrr,codigoResiduoLer) codigoResiduoLerAtual,APAGuia.* FROM APAGuia ");
workbook.AddDataSource("d", dt);
var dtp = GetDataTable(con, "SELECT Instituicao Empresa,* FROM Parametros");
workbook.AddDataSource("p", dtp);
wb = workbook.GenerateReport();
wb.Save(@"c:\anexos\xLstAPAGuia02.xlsx", SaveFileFormat.Xlsx);
con.Close();
}
}
Stack:
System.Data.dll!System.Data.DataRow.GetDataColumn(string columnName)
System.Data.dll!System.Data.DataRow.this[string].get(string columnName) GrapeCity.Documents.Excel.dll!GrapeCity.Documents.Excel.as6.ar4(string A_0) GrapeCity.Documents.Excel.dll!GrapeCity.Documents.Excel.atb.a(string A_0, object A_1)
GrapeCity.Documents.Excel.dll!GrapeCity.Documents.Excel.atb.a(string A_0, object A_1) GrapeCity.Documents.Excel.dll!GrapeCity.Documents.Excel.auo.a(GrapeCity.Documents.Excel.gz A_0, string A_1, string A_2, object A_3)
GrapeCity.Documents.Excel.dll!GrapeCity.Documents.Excel.auo.a(string A_0)
GrapeCity.Documents.Excel.dll!GrapeCity.Documents.Excel.aut.a(GrapeCity.Documents.Excel.atl A_0, GrapeCity.Documents.Excel.aug A_1, GrapeCity.Documents.Excel.auo A_2)
GrapeCity.Documents.Excel.dll!GrapeCity.Documents.Excel.aud.a(GrapeCity.Documents.Excel.aug A_0, GrapeCity.Documents.Excel.auo A_1)
GrapeCity.Documents.Excel.dll!GrapeCity.Documents.Excel.aud.a(System.Collections.Generic.List<GrapeCity.Documents.Excel.aug> A_0, GrapeCity.Documents.Excel.h9 A_1, GrapeCity.Documents.Excel.at5 A_2, System.Collections.Generic.Dictionary<string, System.Collections.Generic.Dictionary<string, GrapeCity.Documents.Excel.atl>> A_3, System.Collections.Generic.List<GrapeCity.Documents.Excel.aub> A_4, GrapeCity.Documents.Excel.auo A_5)
GrapeCity.Documents.Excel.dll!GrapeCity.Documents.Excel.aus.axj()
GrapeCity.Documents.Excel.dll!GrapeCity.Documents.Excel.at7.aw2()
GrapeCity.Documents.Excel.dll!GrapeCity.Documents.Excel.Workbook.ProcessTemplate()