正在下载.xlsx格式化问题 [英] Downloading .xlsx formating issue

查看:94
本文介绍了正在下载.xlsx格式化问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码下载.xlsx报告。

错误:: Excel因文件格式和扩展名无效而无法打开文件。

我的报告内容包含两种HTML格式的表格结构。

我的数据限制总是超过10万加上记录。

请为此建议任何替代方案。 />


I am trying to download an .xlsx report using the following code.
Error :: Excel cannot open the file ecause the file format and extension is not valid.
My report contents consist of two tabular structure in HTML format.
My data limit will always exceed 1 lakh plus records.
Kindly suggest any alternative for the same.

  HttpContext.Current.Response.ContentType = "application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
           HttpContext.Current.Response.Write(@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">");
           HttpContext.Current.Response.AppendHeader("content-disposition", "attachment;filename=Reports.xlsx");
           HttpContext.Current.Response.Charset = "utf-8";
           HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250");
           HttpContext.Current.Response.Write("<font style='font-size:10.0pt; font-family:Calibri;'>");

HttpContext.Current.Response.Write("<BR><BR><BR>");
           HttpContext.Current.Response.Write("<Table border='1' bgColor='#ffffff' borderColor='#000000' cellSpacing='0' cellPadding='0' style='font-size:10.0pt; font-family:Calibri;'> <TR>");





从下面的评论中复制的其他信息

没有我不使用Open XML。

我使用HTML表格格式来创建.xlsx格式的响应



additional information copied from comment below
No im not using Open XML.
I am using HTML table format to create the response in .xlsx format

HttpContext.Current.Response.Write("<Table border='1' bgColor='#ffffff' borderColor='#000000' cellSpacing='0' cellPadding='0' style='font-size:10.0pt; font-family:Calibri;'> <TR>");
int columnscount = dtHeader.Columns.Count;

for (int j = 0; j < columnscount; j++)
{
   HttpContext.Current.Response.Write("<Td>");
   HttpContext.Current.Response.Write("");
   HttpContext.Current.Response.Write(dtHeader.Columns[j].ColumnName.ToString());
   HttpContext.Current.Response.Write("");
   HttpContext.Current.Response.Write("</Td>");
}

HttpContext.Current.Response.Write("</TR>");
foreach (DataRow row in dtHeader.Rows)
{
   HttpContext.Current.Response.Write("<TR>");
   for (int i = 0; i < dtHeader.Columns.Count; i++)
   {
      HttpContext.Current.Response.Write("<Td>");
      HttpContext.Current.Response.Write(row[i].ToString());
      HttpContext.Current.Response.Write("</Td>");
   }

   HttpContext.Current.Response.Write("</TR>");
}
HttpContext.Current.Response.Write("</Table>");

推荐答案

我只是看到你创建了一个html文档,而不是xlsx - 那么为什么你想知道错误信息 - 这是非常有表现力 - 错误的格式和扩展不匹配 - 所以解决方案应该是:要么创建一个有效的xlsx或一个HTML,你不同意吗?
I just see you creating a html doc, not an xlsx - So why you wonder about the error message - which is very expressive - wrong format and extension not matching - So the solution should be: either create a valid xlsx or a html, don't you agree?


这篇关于正在下载.xlsx格式化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆