示例#1
0
        public void WriteExcelTest()
        {
            string       filePath = @"d:\testdata\test.xlsx";
            ExcelOperate ExlSave  = new ExcelOperate();

            ExlSave.OledbRead(filePath);
            bool result = ExlSave.OledbWrite(filePath);

            Assert.IsTrue(result);
        }
示例#2
0
    protected void btnExport_Click(object sender, EventArgs e)
    {
        Dictionary <string, string> dic = new Dictionary <string, string>();

        dic.Add("姓名", "姓名");
        dic.Add("序号", "序号");
        DataTable dt = GetDataTable();

        ExcelOperate.ToExcel(dt, dic, "cs.xls");
    }
示例#3
0
    protected void btnImport_Click(object sender, EventArgs e)
    {
        string path = Server.MapPath("~/Temp/");

        if (fileUpload.HasFile)
        {
            fileUpload.SaveAs(path + fileUpload.FileName);
        }

        DataTable dt = ExcelOperate.ToDataTable(path + fileUpload.FileName);

        gvPS.DataSource = dt;
        gvPS.DataBind();
    }
示例#4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        UserID = CurrentUser.ID;
        string typeValue = Request.QueryString["typeValue"];
        string Json      = "";

        try
        {
            if (typeValue == "SaveUploadInfo")
            {
                string ResID = "";
                if (Request["ResID"] != null)
                {
                    ResID = Request["ResID"].ToString();
                }
                SaveUploadInfo(ResID);
            }
            else if (typeValue == "LoadUploadInfo")
            {
                Json           = "[{'UploadFileName':'" + UploadFileName.Substring(0, UploadFileName.Length - 1) + "','UploadPathUrl':'" + UploadPathUrl + "','FileSize':'" + FileSize + "'}]";
                UploadFileName = "";
                FileSize       = "";
            }
            else if (typeValue == "GetUploadInfo")
            {
                string ResID       = Request.QueryString["ResID"];
                string ParentResID = Request.QueryString["ParentResID"];
                string ParentRecID = Request.QueryString["ParentRecID"];

                Json = GetFilesInfo(ResID, ParentResID, ParentRecID);
            }
            else if (typeValue == "LoadUploadInfo")
            {
                Json           = "[{'UploadFileName':'" + UploadFileName.Substring(0, UploadFileName.Length - 1) + "','UploadPathUrl':'" + UploadPathUrl + "','FileSize':'" + FileSize + "'}]";
                UploadFileName = "";
                FileSize       = "";
            }
            else if (typeValue == "DeleteDoc")
            {
                string ResID       = Request["ResID"].ToString();
                string RecID       = Request["RecID"].ToString();
                string FilePathUrl = Request["FilePathUrl"];

                Json = DeleteDoc(ResID, RecID, UserID);
            }
            else if (typeValue == "DeleteFile")
            {
                string FilePathUrl = Request["FilePathUrl"];
                if (DeleteFile(FilePathUrl))
                {
                    Json = "{\"success\":true}";
                }
                else
                {
                    Json = "{\"success\":false}";
                }
            }
            else if (typeValue == "ImportFile")
            {
                string             ResID = Request["ResID"];
                HttpFileCollection httpFileCollection = Request.Files;
                HttpPostedFile     file = null;
                if (httpFileCollection.Count > 0)
                {
                    file = httpFileCollection[0];
                }
                if (file != null)
                {
                    //获取上传的文件,并转为文件流
                    Stream stream = file.InputStream;
                    byte[] bytes  = new byte[stream.Length];
                    stream.Read(bytes, 0, bytes.Length);
                    DoExcel doexcel = new DoExcel();
                    //Excel中的第一行将作为列名
                    DataTable dt = doexcel.ImportExcel(stream);
                    ExcelOperate.SetDaoRuAccess(dt, ResID);
                    Json = "{\"success\":true,\"msg\":'上传成功!'}";
                }
                else
                {
                    Json = "{\"success\":false,\"msg\":'上传文件失败!'}";
                }
            }
            Response.Write(Json);
        }
        catch (Exception ex)
        {
            Log.Error(ex.ToString());
            //throw;
        }
    }