Explorar el Código

导出excel未提交

machenyang %!s(int64=8) %!d(string=hace) años
padre
commit
3cfe0c98cd
Se han modificado 1 ficheros con 22 adiciones y 128 borrados
  1. 22 128
      codegit/CallCenterCommon/CallCenter.Utility/NPOI/NPOIHelper.cs

+ 22 - 128
codegit/CallCenterCommon/CallCenter.Utility/NPOI/NPOIHelper.cs

@@ -9,6 +9,7 @@ using NPOI.SS.UserModel;
9 9
 using NPOI.SS.Util;
10 10
 using NPOI.XSSF.UserModel;
11 11
 using CallCenterApi.DB;
12
+using System.Collections.Generic;
12 13
 
13 14
 namespace CallCenter.Utility
14 15
 {
@@ -257,12 +258,10 @@ namespace CallCenter.Utility
257 258
         /// <param name="dt"></param>
258 259
         /// <param name="typeclass">仪器或试剂</param>
259 260
         /// <returns></returns>
260
-        public string ExportToExcelForGDLX(string Name, DataTable dt, string typeclass, string[] colnames, int[] erows)
261
+        public string ExportToExcelForGDLX(string Name, DataTable dt, string typeclass, List<string> colnames, List<int> erows, List<string> secolnames)
261 262
         {
262 263
             try
263 264
             {
264
-                //if (dt.Rows.Count > 0)
265
-                //{
266 265
                 HSSFWorkbook workbook = new HSSFWorkbook();
267 266
                 ISheet sheet = workbook.CreateSheet("Sheet1");
268 267
 
@@ -286,93 +285,26 @@ namespace CallCenter.Utility
286 285
                 //用column name 作为列名
287 286
                 int icolIndex = 0;
288 287
                 IRow headerRow = sheet.CreateRow(0);
289
-                //if (cols == null || (cols != null && cols.Length == 0))
290
-                //{
291
-                //    foreach (DataColumn dc in dt.Columns)
292
-                //    {
293
-                //        ICell cell = headerRow.CreateCell(icolIndex);
294
-                //        cell.SetCellValue(dc.ColumnName);
295
-                //        cell.CellStyle = HeadercellStyle;
296
-                //        icolIndex++;
297
-                //    }
298
-                //}
299
-                //else
300
-                //{
301
-                for (int i = 0; i < colnames.Length; i++)
288
+                
289
+                for (int i = 0; i < colnames.Count; i++)
302 290
                 {
303
-                    ICell cell = headerRow.CreateCell(icolIndex);
304
-                    if (colnames[i] != "")
305
-                    {
306
-                        SetCellRangeAddress(sheet, 0, 0, erows[i], erows[i + 1]);
307
-                    }
291
+                    ICell cell = headerRow.CreateCell(i);
308 292
                     cell.SetCellValue(colnames[i]);
309 293
                     cell.CellStyle = HeadercellStyle;
310
-                    icolIndex++;
294
+                    //SetCellRangeAddress(sheet, 0, 0, erows[i * 2], erows[i * 2 + 1]);
295
+                }
296
+                
297
+                for (int k = 0; k < erows.Count / 2; k++)
298
+                {
299
+                    SetCellRangeAddress(sheet, 0, 0, erows[k * 2], erows[k * 2 + 1]);
300
+                }
301
+                //添加第二行标题
302
+                IRow SecRow = sheet.CreateRow(1);
303
+                for (int i = 0; i < secolnames.Count; i++)
304
+                {
305
+                    ICell cell = SecRow.CreateCell(i);
306
+                    cell.SetCellValue(secolnames[i].ToString());
311 307
                 }
312
-                //}
313
-
314
-
315
-
316
-                //IRow headerRow = sheet.CreateRow(0);
317
-                ////下面一行
318
-                //IRow Row3layer = sheet.CreateRow(1);
319
-
320
-                #region 添加表格标题
321
-                //DataTable dtNew = new DataTable();
322
-                ////获取仪器类型
323
-                //DataTable dtyq = new DataTable();
324
-                //var sqlyq = " select * from [dbo].[T_RepositoryCategory] where F_ParentId=(select F_CategoryId from[dbo].[T_RepositoryCategory] where F_CategoryName='" + typeclass + "' and F_ParentId = 0 and F_DeleteFlag = 0) ";
325
-                //dtyq = DbHelperSQL.Query(sqlyq).Tables[0];
326
-                //DataRow dr2layer = dtNew.NewRow();
327
-                //dr2layer[0] = "";
328
-                //DataRow dr3layer = dtNew.NewRow();
329
-                //dr3layer[0] = "坐席人员";
330
-
331
-                //int partend = 0;
332
-
333
-                //if (dtyq != null && dtyq.Rows.Count > 0)
334
-                //{
335
-                //    ICell cell = headerRow.CreateCell(0);
336
-                //    cell.SetCellValue("");
337
-                //    for (int i = 0; i < dtyq.Rows.Count; i++)
338
-                //    {
339
-                //        string colname = dtyq.Rows[i]["F_CategoryName"].ToString();
340
-                //        dr2layer[i] = colname;
341
-                //        //获取三级仪器类型
342
-                //        int cataid = Convert.ToInt32(dtyq.Rows[i]["F_CategoryId"].ToString());
343
-                //        DataTable dtyq3layer = new DataTable();
344
-                //        var sqlyq3layer = " select * from [dbo].[T_RepositoryCategory] where F_ParentId=(select F_CategoryId from[dbo].[T_RepositoryCategory] where 1=1 and F_ParentId = " + cataid + " and F_DeleteFlag = 0) ";
345
-                //        dtyq3layer = DbHelperSQL.Query(sqlyq3layer).Tables[0];
346
-                //        int beginj = 1;
347
-                //        int endj = dtyq3layer.Rows.Count;
348
-                //        if (i != 0)
349
-                //        {
350
-                //            beginj = endj;
351
-                //            endj += dtyq3layer.Rows.Count;
352
-                //        }
353
-
354
-                //        ICell cell3layername = Row3layer.CreateCell(0);
355
-                //        cell3layername.SetCellValue("姓名");
356
-                //        for (int j = beginj; j <= endj; j++)
357
-                //        {
358
-                //            string col3layername = dtyq3layer.Rows[i]["F_CategoryName"].ToString();
359
-                //            dr3layer[j] = col3layername;
360
-
361
-                //            ICell cells = headerRow.CreateCell(j);
362
-                //            cells.SetCellValue(colname);
363
-
364
-                //            ICell cell3layer = Row3layer.CreateCell(j);
365
-                //            cell3layer.SetCellValue(col3layername);
366
-                //        }
367
-                //        SetCellRangeAddress(sheet, 0, 0, beginj, endj);
368
-                //        partend += endj;
369
-                //    }
370
-                //    ICell cell3layerlast = Row3layer.CreateCell(partend);
371
-                //    cell3layerlast.SetCellValue("");
372
-                //    ICell cellsum = headerRow.CreateCell(0);
373
-                //    cell.SetCellValue("总计");
374
-                //}
375
-                #endregion
376 308
 
377 309
                 ICellStyle cellStyle = workbook.CreateCellStyle();
378 310
 
@@ -389,49 +321,11 @@ namespace CallCenter.Utility
389 321
                 cellStyle.SetFont(cellfont);
390 322
 
391 323
                 //建立内容行
392
-                //int iRowIndex = 0;
393
-                //foreach (DataRow dr in dt.Rows)
394
-                //{
395
-                //    int iCellIndex = 0;
396
-                //    IRow irow = sheet.CreateRow(iRowIndex + 2);
397
-                //    for (int i = 0; i < dt.Columns.Count; i++)
398
-                //    {
399
-                //        string strsj = string.Empty;
400
-                //        if (dr[i] != null)
401
-                //        {
402
-                //            strsj = dr[i].ToString();
403
-                //        }
404
-                //        ICell cell = irow.CreateCell(iCellIndex);
405
-                //        cell.SetCellValue(strsj);
406
-                //        cell.CellStyle = cellStyle;
407
-                //        iCellIndex++;
408
-                //    }
409
-                //    iRowIndex++;
410
-                //}
411
-                //for (int n = 2; n < dt.Rows.Count; n++)
412
-                //{
413
-                //    int iCellIndex = 0;
414
-                //    IRow irow = sheet.CreateRow(iRowIndex + 2);
415
-                //    for (int i = 0; i < dt.Columns.Count; i++)
416
-                //    {
417
-                //        string strsj = string.Empty;
418
-                //        if (dt.Rows[n] != null)
419
-                //        {
420
-                //            strsj = dt.Rows[n].ToString();
421
-                //        }
422
-                //        ICell cell = irow.CreateCell(iCellIndex);
423
-                //        cell.SetCellValue(strsj);
424
-                //        cell.CellStyle = cellStyle;
425
-                //        iCellIndex++;
426
-                //    }
427
-                //    iRowIndex++;
428
-                //}
429
-                //建立内容行
430 324
                 int iRowIndex = 0;
431 325
                 foreach (DataRow dr in dt.Rows)
432 326
                 {
433 327
                     int iCellIndex = 0;
434
-                    IRow irow = sheet.CreateRow(iRowIndex + 1);
328
+                    IRow irow = sheet.CreateRow(iRowIndex + 2);
435 329
                     for (int i = 0; i < dt.Columns.Count; i++)
436 330
                     {
437 331
                         string strsj = string.Empty;
@@ -474,12 +368,12 @@ namespace CallCenter.Utility
474 368
 
475 369
                     curContext.Response.End();
476 370
                 }
477
-                //}
371
+                
478 372
                 return "";
479 373
             }
480
-            catch
374
+            catch (Exception e)
481 375
             {
482
-                return "导出失败!";
376
+                return "导出失败!" + e.Message;
483 377
             }
484 378
         }
485 379