生成Excel文件错误 [英] generating Excel file error

查看:206
本文介绍了生成Excel文件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code在传统的ASP生成Excel文件中,code是简单,它的工作原理。我运行IIS 7.0在Windows Vista上的86 code。两个问题,

I am using the following code in classic ASP to generate Excel file, the code is simple and it works. I run the code under IIS 7.0 on Windows Vista x86. Two issues,


  1. 有一个奇怪的警告框,这里是屏幕快照

http://i27.tinypic.com/2n81udw.jpg


  1. 所有细胞的背景是白色的,这里没有表现出每个细胞的边界是屏幕快照,

http://i25.tinypic.com/vy5t2d.jpg

我的code,

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<%

function writeXlsHttpHeaders(filename){
    Response.ContentType = "application/vnd.ms-excel";
    Response.Charset = "utf-8";
    Response.AddHeader("Content-Disposition", 
            "attachment; filename="+filename+".xls");
}

function getXlsStart(){
    return ""
    + "<html>\n"
    + "<head>\n"
    + "<meta http-equiv=\"Content-Type\" "
    + "content=\"text/html; charset=UTF-8\">\n"
    + "<style type=\"text/css\">\n"
    + "html, body, table {\n"
    + "    margin: 0;\n"
    + "    padding: 0;\n"
    + "    font-size: 11pt;\n"
    + "}\n"
    + "table, th, td { \n"
    + "    border: 0.1pt solid #D0D7E5;\n"
    + "    border-collapse: collapse;\n"
    + "    border-spacing: 0;\n"
    + "}\n"
    + "</style>\n"
    + "</head>\n"
    + "<body>\n"
    + "<table>\n"
    + "";
}

function getXlsEnd(){
    return ""
    + "</table>\n"
    + "</body>\n"
    + "</html>"
    + "";
}

function xlsEscape(val){
    if (typeof val === "number") {
        return val.toString(10).replace(".", ",");
    } else if (typeof val === "string") {
        return Server.HTMLEncode(val);
    } else if (val === null)  {
        return "#NULL#";
    } else if (val === undefined)  {
        return "#UNDEFINED#";
    } else {
        return "#ERROR#";
    }
}

function writeXls(filename, data, columnCount){
    writeXlsHttpHeaders(filename);
    Response.Write(getXlsStart());
    var columnCount = 2;
    for (var i=0, il=10; i<il; i+=columnCount) {
        Response.Write("<tr>");
        for (var j=0; j<columnCount; j++) {
            Response.Write("<td>");
            Response.Write(xlsEscape("Data"));
            Response.Write("</td>");
        }
        Response.Write("</tr>\n");
        // prevent Response Buffering Limit Exceeded
        if (i % 1000 === 0) {
            Response.Flush();
        }
    }
    Response.Write(getXlsEnd());
}

function main(){
    var filetype = Request.QueryString("filetype")();
    var filename = "filename";

    Response.Clear();
    writeXls(filename);
    Response.End();
}

main();

%>

任何解决方案?

在此先感谢,
乔治

thanks in advance, George

推荐答案

一个。有一个奇怪的警告框...

A. There is a weird warning box...

您提供了文件的扩展名设置为XLS HTML。这是一个安全冲突在过去一年左右出台。是否改变扩展HTM避免安全提示?

You are serving up HTML with the file extension set at xls. This is a security violation introduced in the last year or so. Does changing the extension to htm avoid the security prompt?

乙。因为你的HTML表格只包含两列,5行。有没有其他的细胞,因此没有边界。为了避免这种情况,我是pretty确定你需要来提供CVS,工作簿XML或其他。 (在我看来,我喜欢,有没有国界的,但大多数人并不知道。)

B. Because your HTML Table only contains two columns and five rows. There are no other "cells", so there are no borders. In order to avoid this, I am pretty sure you need to serve up CVS, Workbook XML, or "other". (In my opinion, I like that there are no borders, but most people do not.)

℃。 ... IIS 7.0下的code在Windows Vista x86的...

C. ...code under IIS 7.0 on Windows Vista x86...

这是一个Excel和安全问题,并没有涉及到IIS或Windows。

This is an Excel and security issue, and not related to IIS or Windows.

ð。对不起,因为我一直在使用Syncfusion 3.0过去的几年里,我没有给你一个明确的答案。它提供了正确的Excel工作簿的格式,也没有问题。

D. Sorry, I don't have a specific answer for you because I been using Syncfusion 3.0 the last few years. It serves up the correct Excel formatted workbooks and there is no issues.

这篇关于生成Excel文件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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