7
I did an export routine for the excel
, using StreamWriter
, but it causes me a problem. I can’t get the name of the columns that come in select. To make the header, I had to put it in the hand. This would not be the problem, the question is when opening the file, it gives a message that the file is not compatible, but then it opens normally. Does anyone have a different path from this? Below the code that generates excel, based on a select in Oracle
.
protected void btnExport_Click(object sender, EventArgs e)
{
string caminho = @"C:\\Teste_Xls\\ListaCliente.xlsx";
string error = string.Empty;
DataExport dataExport = new DataExport();
var connection = ConfigurationManager.ConnectionStrings["DTOP"].ConnectionString;
OracleConnection conn = new OracleConnection(connection);
using (StreamWriter sw = File.CreateText(caminho))
{
using (var connectionOracle = new OracleConnection(connection))
{
try
{
var cmd = new OracleCommand(query, conn);
conn.Open();
using (OracleDataReader reader = cmd.ExecuteReader())
{
sw.WriteLine("Data Inclusao" + "\t" + "Tipo de Tabela" + "\t" + "Tabela" + "\t" + "Codigo" + "\t" + "TUSS");
while (reader.Read())
{
DateTime dtInclusao = Convert.ToDateTime(reader[0]);
string tipoTabela = reader[1].ToString();
string tabela = reader[2].ToString();
Int64 codigo = Convert.ToInt64(reader[3]);
string tuss = reader[4].ToString();
sw.WriteLine(dtInclusao + "\t" + tipoTabela + "\t" + tabela + "\t" + codigo + "\t" + tuss);
}
}
}
catch(Exception ex)
{
error = ex.Message;
}
}
}
//CreateExcelFile.CreateExcelDocument(listaDataExport, @"C:\\Teste_Xls\\ListaCliente.xlsx");
}
dude, look up the Excel API itself to "Microsoft.Interop.Excel" might help.
– Guilherme Golfetto