Plugins/ExcelToJson.aspx.cs

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data.OleDb;
using EKETEAM.FrameWork;
using LitJson;

public partial class Plugins_ExcelToJson : System.Web.UI.Page
{
    string path = eParameters.QueryString("path");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (path.ToLower().IndexOf("upload") == -1) eResult.Error("路径有误!");
        path = path.Substring(path.ToLower().IndexOf("upload/"));
        eFileInfo fi = new eFileInfo(path);
        string tagfolder = fi.Path;
        tagfolder += fi.Name + fi.fileExtension;

        string pathname = Server.MapPath("~/" + tagfolder);
        if (!File.Exists(pathname)) eResult.Error("文件不存在或已被删除!");

        OleDbConnection Oleconn;
        switch (fi.fileExtension)
        {
            case ".xlsx":
                Oleconn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pathname + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1;\";");
                break;
            case ".xls":
                if (IsText(pathname))
                {
                    Oleconn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathname + ";Extended Properties=\"HTML Import;HDR=Yes;\"");
                }
                else
                {
                    Oleconn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;Excel 8.0;ReadOnly=True;HDR=YES;IMEX=1;database=" + pathname + ";");
                }
                break;
            case ".csv":
                Oleconn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"" + fi.Path + "\";Extended Properties=\"text;HDR=Yes;FMT=Delimited;\"");
                break;
            default:
                Oleconn = new OleDbConnection();
                break;
        }

        try
        {
            Oleconn.Open();
        }
        catch
        {
            eResult.Error("文件格式有误!");
        }
        DataTable dt = Oleconn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
        if (dt.Rows.Count == 0) eResult.Error("文件有误!");
        DataRow dr = dt.Rows[0];
后面还有 67 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。