Beispiel #1
0
        public async Task<ActionResult> ExportToExcelEx(IVTestDataForPackageQueryViewModel model)
        {
            //            StringBuilder where = new StringBuilder();
            //            char[] splitChars = new char[] { ',', '$' };
            //            string[] packageNos = model.PackageNo.TrimEnd(splitChars).Split(splitChars);


            //            if (packageNos.Length <= 1)
            //            {
            //                where.AppendFormat("'" + packageNos[0] + "'");
            //            }
            //            else
            //            {
            //                foreach (string package in packageNos)
            //                {
            //                    where.AppendFormat("'{0}',", package);
            //                }
            //                where.Remove(where.Length - 1, 1);
            //            }
            //            String sql = string.Format(@"select t1.PACKAGE_NO,t1.ITEM_NO,t1.OBJECT_NUMBER,t1.ORDER_NUMBER,t1.MATERIAL_CODE,
            //                                            t3.GRADE,t3.COLOR,
            //                                            t2.PM,t2.ISC,t2.IPM,t2.VOC,t2.VPM,t2.FF,t2.EFF,t2.RS,t2.RSH,t2.AMBIENTTEMP,t2.SENSORTEMP,t2.INTENSITY, 
            //                                            t2.COEF_PMAX,t2.COEF_ISC,t2.COEF_IMAX,t2.COEF_VOC,t2.COEF_VMAX,t2.COEF_FF,t2.DEC_CTM,t3.ATTR_1, 
            //                                            t2.PS_CODE,t2.PS_ITEM_NO,t4.PM_NAME,
            //                                            t2.PS_SUBCODE
            //                                            from WIP_PACKAGE_DETAIL t1
            //                                            inner join WIP_LOT t3 on t1.OBJECT_NUMBER =t3.LOT_NUMBER
            //                                            left join ZWIP_IV_TEST t2  on t1.OBJECT_NUMBER =t2.LOT_NUMBER
            //                                            inner join ZFMM_POWERSET t4 on t2.PS_CODE = t4.PS_CODE and t2.PS_ITEM_NO = t4.ITEM_NO 
            //                                            where t2.IS_DEFAULT =1
            //                                            and t1.PACKAGE_NO in (
            //                                            {0}
            //                                            ) order by PACKAGE_NO,ITEM_NO", where);
            //            DataTable dt = new DataTable();
            //            using (DBServiceClient client = new DBServiceClient())
            //            {
            //                MethodReturnResult<DataTable> result = client.ExecuteQuery(sql);
            //                if (result.Code == 0)
            //                {
            //                    dt = result.Data;
            //                }
            //            }
            DataTable dt = new DataTable();
            using (PackageQueryServiceClient client = new PackageQueryServiceClient())
            {
                RPTpackagelistParameter param = new RPTpackagelistParameter();
                param.PackageNo = model.PackageNo;
                param.LotNumber = model.LotNumber;
                await Task.Run(() =>
                {
                    PagingConfig cfg = new PagingConfig()
                    {
                        OrderBy = "Key.PackageNo,ItemNo",
                        Where = GetQueryCondition(model)
                    };
                    // MethodReturnResult<IList<PackageDetail>> result = client.GetDetail(ref cfg);
                    MethodReturnResult<DataSet> ds = client.GetRPTpackagelist(param);
                    dt = ds.Data.Tables[0];
                    //if (result.Code == 0)
                    //{
                    //    ViewBag.PagingConfig = cfg;
                    //    ViewBag.List = result.Data;
                    //    ViewBag.HistoryList = ds;
                    //}
                });
            }
            //创建工作薄。
            IWorkbook wb = new HSSFWorkbook();
            //设置EXCEL格式
            ICellStyle style = wb.CreateCellStyle();
            style.FillForegroundColor = 10;
            //有边框
            style.BorderBottom = BorderStyle.Thin;
            style.BorderLeft = BorderStyle.Thin;
            style.BorderRight = BorderStyle.Thin;
            style.BorderTop = BorderStyle.Thin;
            IFont font = wb.CreateFont();
            font.Boldweight = 10;
            style.SetFont(font);

            ISheet ws = null;

            for (int j = 0; j < dt.Rows.Count; j++)
            {
                if (j % 65535 == 0)
                {
                    ws = wb.CreateSheet();
                    IRow row = ws.CreateRow(0);
                    #region //列名
                    ICell cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue(StringResource.ItemNo);  //项目号

                    cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("包装号");

                    cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("项目号");

                    cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("批次号");

                    cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("工单号");

                    cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("物料编码");

                    cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("等级");

                    cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("花色");

                    //cell = row.CreateCell(row.Cells.Count);
                    //cell.CellStyle = style;
                    //cell.SetCellValue("功率");

                    //cell = row.CreateCell(row.Cells.Count);
                    //cell.CellStyle = style;
                    //cell.SetCellValue("短路电流");

                    //cell = row.CreateCell(row.Cells.Count);
                    //cell.CellStyle = style;
                    //cell.SetCellValue("最大电流");

                    //cell = row.CreateCell(row.Cells.Count);
                    //cell.CellStyle = style;
                    //cell.SetCellValue("开路电压");

                    //cell = row.CreateCell(row.Cells.Count);
                    //cell.CellStyle = style;
                    //cell.SetCellValue("最大电压");

                    //cell = row.CreateCell(row.Cells.Count);
                    //cell.CellStyle = style;
                    //cell.SetCellValue("填充因子");

                    //cell = row.CreateCell(row.Cells.Count);
                    //cell.CellStyle = style;
                    //cell.SetCellValue("转换效率");

                    //cell = row.CreateCell(row.Cells.Count);
                    //cell.CellStyle = style;
                    //cell.SetCellValue("串联电阻");

                    //cell = row.CreateCell(row.Cells.Count);
                    //cell.CellStyle = style;
                    //cell.SetCellValue("并联电阻");

                    //cell = row.CreateCell(row.Cells.Count);
                    //cell.CellStyle = style;
                    //cell.SetCellValue("背板温度");

                    //cell = row.CreateCell(row.Cells.Count);
                    //cell.CellStyle = style;
                    //cell.SetCellValue("环境温度");

                    //cell = row.CreateCell(row.Cells.Count);
                    //cell.CellStyle = style;
                    //cell.SetCellValue("光强");

                    cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("功率");

                    cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("最大电流");

                    cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("电流");

                    cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("最大电压");

                    cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("电压");

                    cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("填充因子");

                    cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("CTM");

                    cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("电池片效率");

                    cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("分档代码");

                    cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("分档项目号");

                    cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("分档名称");

                    cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("子分档代码");

                    #endregion
                    font.Boldweight = 5;
                }
                IRow rowData = ws.CreateRow(j + 1);

                #region //数据
                ICell cellData = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(j + 1);  //项目号

                cellData = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["PACKAGE_NO"].ToString());

                cellData = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["ITEM_NO"].ToString());

                cellData = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["OBJECT_NUMBER"].ToString());

                cellData = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["ORDER_NUMBER"].ToString());

                cellData = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["MATERIAL_CODE"].ToString());

                cellData = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["GRADE"].ToString());

                cellData = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["COLOR"].ToString());

                //cellData = rowData.CreateCell(rowData.Cells.Count);
                //cellData.CellStyle = style;
                //cellData.SetCellValue(dt.Rows[j]["PM"].ToString());

                //cellData = rowData.CreateCell(rowData.Cells.Count);
                //cellData.CellStyle = style;
                //cellData.SetCellValue(dt.Rows[j]["ISC"].ToString());

                //cellData = rowData.CreateCell(rowData.Cells.Count);
                //cellData.CellStyle = style;
                //cellData.SetCellValue(dt.Rows[j]["IPM"].ToString());

                //cellData = rowData.CreateCell(rowData.Cells.Count);
                //cellData.CellStyle = style;
                //cellData.SetCellValue(dt.Rows[j]["VOC"].ToString());

                //cellData = rowData.CreateCell(rowData.Cells.Count);
                //cellData.CellStyle = style;
                //cellData.SetCellValue(dt.Rows[j]["VPM"].ToString());

                //cellData = rowData.CreateCell(rowData.Cells.Count);
                //cellData.CellStyle = style;
                //cellData.SetCellValue(dt.Rows[j]["FF"].ToString());

                //cellData = rowData.CreateCell(rowData.Cells.Count);
                //cellData.CellStyle = style;
                //cellData.SetCellValue(dt.Rows[j]["EFF"].ToString());

                //cellData = rowData.CreateCell(rowData.Cells.Count);
                //cellData.CellStyle = style;
                //cellData.SetCellValue(dt.Rows[j]["RS"].ToString());

                //cellData = rowData.CreateCell(rowData.Cells.Count);
                //cellData.CellStyle = style;
                //cellData.SetCellValue(dt.Rows[j]["RSH"].ToString());

                //cellData = rowData.CreateCell(rowData.Cells.Count);
                //cellData.CellStyle = style;
                //cellData.SetCellValue(dt.Rows[j]["AMBIENTTEMP"].ToString());

                //cellData = rowData.CreateCell(rowData.Cells.Count);
                //cellData.CellStyle = style;
                //cellData.SetCellValue(dt.Rows[j]["SENSORTEMP"].ToString());

                //cellData = rowData.CreateCell(rowData.Cells.Count);
                //cellData.CellStyle = style;
                //cellData.SetCellValue(dt.Rows[j]["INTENSITY"].ToString());

                cellData = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["COEF_PMAX"].ToString());

                cellData = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["COEF_ISC"].ToString());

                cellData = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["COEF_IMAX"].ToString());

                cellData = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["COEF_VOC"].ToString());

                cellData = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["COEF_VMAX"].ToString());

                cellData = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["COEF_FF"].ToString());

                cellData = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["DEC_CTM"].ToString());

                cellData = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["CellEfficiency"].ToString());

                cellData = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["PS_CODE"].ToString());

                cellData = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["PS_ITEM_NO"].ToString());

                cellData = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["PM_NAME"].ToString());

                cellData = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["PS_SUBCODE"].ToString());

                #endregion
            }

            MemoryStream ms = new MemoryStream();
            wb.Write(ms);
            ms.Flush();
            ms.Position = 0;
            return File(ms, "application/vnd.ms-excel", "IVTestDataData.xls");
        }