Excel数据无法正确显示 [英] Excel datas are not displaying properly

查看:94
本文介绍了Excel数据无法正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的表单中,我正在使用一个附加文档的选项.这样,用户能够附加各种文档.用户可以选择查看附加的文档,同时单击查看按钮,他们可以查看文档.对于所有类型的文档,除了excel以外,它都可以正常工作.原始数据未显示,正在显示一些未知数据.谁能帮我解决这个问题.这是代码:


Hi,

In my form I am using an option to attach a document. In this, the user is able to attach all kinds of documents. The user has the option to view the attached document, while clicking the view button they can view the document. For all types of document it works fine except for the excel. The original data is not displaying, it''s displaying some unknown datas. Can anyone help me to solve this issue. Here is the code:


protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
try
{
    string fileName = ((Label)GridView1.Rows[e.NewSelectedIndex].FindControl("lnkFileName")).Text;
    Session["fileopen"] = fileName;
    string path = GetPath() + fileName;
    FileInfo file = new FileInfo(path);
    if (file.Exists)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MySqlDatabase"].ConnectionString);
        con.Open();
        cmd = new SqlCommand("select * from FileTypes with(nolock) where extension=''" + file.Extension + "''", con);
        cmd.CommandTimeout = 0;
        myReader = cmd.ExecuteReader();
        cmd.CommandTimeout = 0;
        if (myReader.Read())
        {
            myReader.Close();
            SessionVarriables.ViewFileSession = path;
            SessionVarriables.ViewFileNameSession = "File";
            Response.Redirect("ViewDocument.aspx");
        }
        else
        {
            myReader.Close();
            Message1("Cannot open selected file");
            return;
        }
        con.Close();
    }
    else
    {
        Message1("File not found");
    }
}
catch (Exception ex)
{
    UserUtil.Message(ex.Message, this);

}

}



在此先感谢.



Thanks in advance.

推荐答案

ViewDocument.aspx有什么作用?听起来好像是以文本文件形式打开Excel文件,但由于它是二进制文件,因此无法正常工作.只需响应即可.重定向到xls文件,用户计算机将下载它.
What does ViewDocument.aspx do? It sounds like it is opening the Excel file as a text file, which won''t work because it is binary. Just response.Redirect to the xls file and the users computer will download it.


这篇关于Excel数据无法正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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