以.zip格式导出到Excel文件以减小文件大小。如何在将xmldata发送到客户端之前进行压缩? [英] Export to Excel file as .zip to reduce file size. How to compress xmldata before sending it to the client?

查看:238
本文介绍了以.zip格式导出到Excel文件以减小文件大小。如何在将xmldata发送到客户端之前进行压缩?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢在将数据作为excel文件提供给客户端之前压缩xmldata。我试图压缩和作为一个.zip文件。它不工作这里是我的代码下面。请帮助

I like to compress the xmldata before the data is provided to the client as an excel file. I am trying to compress and deliver it as a .zip file. its not working Here's my code below. Please help

我试过压缩它,将其转换为字节等等。下面的代码的问题是,XSL转换没有正常发生,输出excel文件是raw xml结尾有一些.net异常。 (这是我看到的.xls文件,在下载的结束)
在我开始工作压缩之前,我的下面的代码工作正常,从xml输入正确格式化的excel文件。 excel文件是如此的好,你甚至不能告诉它是从XML。
pLEASE HELP with compression

I tried compressing it, converting it to bytes etc etc. The issue with below code is, the XSL transformation is not happening properly and the output excel file is raw xml with some .net exception at the end. (that's what I see on the .xls file that's downloaded at the end) Before I started working on compression my below code was working fine that gives properly formatted excel file from the xml input. the excel file is so nice you can't even tell it was from XML. pLEASE HELP with compression

 Dim attachment As String = "attachment; filename=DataDownload.xls"
        Response.ClearContent()
        Response.AddHeader("content-disposition", attachment)
        Response.ContentType = "application/vnd.ms-excel"
        'Response.ContentType = "text/csv"

        Response.Charset = ""
        Dim ds As New DataSet()

        Dim objXMLReader As XmlReader
        objXMLReader = Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteXmlReader(ConnectionString, CommandType.StoredProcedure, "SPName")

        ds.ReadXml(objXMLReader)

        Dim xdd As New XmlDataDocument(ds)
        Dim xt As New XslCompiledTransform()
        'xt.Transform(xdd, Nothing, Response.OutputStream)

        Dim bytearr() As Byte
        bytearr = System.Text.Encoding.Default.GetBytes(xdd.OuterXml)

        Dim objMemStream As New MemoryStream()
        objMemStream.Write(bytearr, 0, bytearr.Length)
        objMemStream.WriteTo(Response.OutputStream)
        xt.Transform(xdd, Nothing, Response.OutputStream)

        Response.End()


推荐答案

为什么不使用XLSX格式而不是XLS?它已经在ZIP文件中压缩了XML-Data。您可以将XLSX文件重命名为ZIP,以验证此操作。

Why you don't use XLSX-Format instead of XLS? It is already XML-Data compressed in a ZIP file. You can rename a XLSX file to ZIP to verify this.

更新:顺便说一下, ContentType 在应该是application / vnd.openxmlformats-officedocument.spreadsheetml.sheet而不是application / vnd.ms-excel。

Updated: By the way, ContentType in the case should be "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" instead of "application/vnd.ms-excel".

这篇关于以.zip格式导出到Excel文件以减小文件大小。如何在将xmldata发送到客户端之前进行压缩?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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