代码改变世界

Excel导出 npol

2013-05-14 20:14  Commander lang  阅读(634)  评论(0编辑  收藏  举报
#region 导出excel
                        bll_common = new DBCommon();
                        lstr = context.Request.Params["_gt_json"];
                        ldi = JsonConvert.DeserializeObject<Joint.BLL.Common.LoadDataInfo>(lstr);
                        strWhere = Joint.BLL.Common.CreateQueryString.GetFilterInfoString(ldi);//查询条件
                        
                        

                        string TemplateFilePath = context.Request.PhysicalApplicationPath + "\\Operation\\BussinessQuitInput\\样品信息列表.xls";//模板路径
                        //ds.Tables.Add(dt);
                        //Joint.BLL.FileDB.FileExcel GetExcel = new Joint.BLL.FileDB.FileExcel();
                        Joint.BLL.FileDB.FileNPOI GetExcel = new Joint.BLL.FileDB.FileNPOI();//方法2(新EXCEL导出 NPOI)
                        Joint.BLL.Data.Bsys_export_plus bll_export = new Bsys_export_plus();
                        if (bll_export.UpdateIsExport(Joint.BLL.Common.CreateQueryString.GetColumnInfoString(ldi, true).Replace("[", "'").Replace("]", "'"), "样品信息列表", "样品信息列表", true) < 0)
                        {
                            //return "[{ code:-2,value:'保存出错!' }]";
                        }
                        else
                        {
                            //string myWhere  = strWhere
                            int RowCount = bll_common.GetRecordCount("View_wt_rw_yp_jg_forseach", "ypbh", strWhere);
                            int PageSize = 2000;//分页大小
                            int ExcelPageSize = 60000;

                            int ExcelTop = 2;
                            int Excelleft = 1;

                            Joint.Common.Office.NPOIExcel myExcelHelp = GetExcel.ExcelExportStep1("样品信息列表", TemplateFilePath);

                            int SheetCount = myExcelHelp.GetSheetCount(RowCount, ExcelPageSize);
                            int DataPageCount = myExcelHelp.GetSheetCount(RowCount, PageSize);
                            if (SheetCount > 1)
                                myExcelHelp.CopyWorkSheets(SheetCount);//第一张表复制多少份(实际数据-1份)
                            int CurrentSheetIndex = 1;//重用变量
                            myExcelHelp.ChangeCurrentWorkSheet(CurrentSheetIndex);

                            strOrder = Joint.BLL.Common.CreateQueryString.GetSortInfoString(ldi);
                            string strCol = Joint.BLL.Common.CreateQueryString.GetColumnInfoString(ldi);

                            for (int i = 1; i <= DataPageCount; i++)
                            {
                                DataSet ds1 = bll_common.GetList(PageSize, i, "View_wt_rw_yp_jg_forseach", "ypbh", strWhere, strCol, strOrder);
                                GetExcel.ExcelExportStep2(myExcelHelp, ds1, "样品信息列表", ExcelTop, Excelleft, ExcelTop>PageSize ?false:true);
                                ExcelTop += PageSize;
                                if (ExcelTop >= ExcelPageSize)
                                {
                                    ExcelTop -= ExcelPageSize;
                                    CurrentSheetIndex++;
                                    if(CurrentSheetIndex  <=SheetCount)
                                        myExcelHelp.ChangeCurrentWorkSheet(CurrentSheetIndex);
                                }
                            }
                            GetExcel.ExcelExportStep3(myExcelHelp);
                        }

                        #endregion