alfinete
Power Member
estou a gerar um excel atraves de html
ele gera o excel no formato xslx
mas ao abri-lo da o seguinte erro
"
excel canot open file xpto.xslx
beacause the file format or file extention is not valid.
verify that the file has not been corrupted and that the file extention matches de format of thr file
"
não estou a perceber pq
ele gera o excel no formato xslx
mas ao abri-lo da o seguinte erro
"
excel canot open file xpto.xslx
beacause the file format or file extention is not valid.
verify that the file has not been corrupted and that the file extention matches de format of thr file
"
não estou a perceber pq
Código:
var Context = HttpContext.Current;
string FinalWord = @"<table style=\"border: 1px solid #5dade2 ;max-width:3000px;width:auto;min-width:700px;\"><tr style=\"border: 1px solid #5dade2 ;background-color: #5dade2;color:#FFFFFF;\"><td style=\"max-width:150px;width:auto;min-width:10px;\">Employee Number</td><td style=\"max-width:150px;width:auto;min-width:10px;\">Name</td><td style=\"max-width:150px;width:auto;min-width:10px;\">ID Number</td><td style=\"max-width:150px;width:auto;min-width:10px;\">NIF</td><td style=\"max-width:150px;width:auto;min-width:10px;\">Entidade Legal</td><td style=\"max-width:150px;width:auto;min-width:10px;\">Morada</td><td style=\"max-width:150px;width:auto;min-width:10px;\">Local</td><td style=\"max-width:150px;width:auto;min-width:10px;\">Cod. Postal</td></tr><tr style=\"border: 1px solid #5dade2;height:40px;\"><td>T00</td><td>João </td><td>106</td><td>197</td><td>Services SA</td><td>Rua Prista</td><td>Lisboa</td><td>1600</td></tr></table>";
string ActualDate = DateTime.Now.ToString(\"yyyyMMdd\");
string StartFileName = string.Format(\"File_{0}_{1}_\", OpID == 1 ? \"V\" : \"N\", ID);
string Extention = \"xlsx\";
string FileName = string.Format(\"{0}{1}.{2}\", StartFileName, ActualDate, Extention);
Context.Response.Clear();
Context.Response.ClearContent();
Context.Response.ClearHeaders();
Context.Response.Buffer = true;
Context.Response.AddHeader(\"content-disposition\", String.Format(\"attachment; filename={0}\", FileName));
Context.Response.AddHeader(\"Content-Type\", \"application/Excel\");
Context.Response.Charset = string.Empty;
// Context.Response.ContentType = \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\";
Context.Response.ContentType = \"application/vnd.ms-excel\";
byte[] Htmlbytes = Encoding.ASCII.GetBytes(FinalWord);
Context.Response.BinaryWrite(Htmlbytes);
Context.Response.Flush();
Context.ApplicationInstance.CompleteRequest();
Context.Response.End();