本文介绍了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.

推荐答案


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

05-28 21:42
查看更多