|
|
|
@ -8,6 +8,7 @@ using System.Linq.Dynamic.Core; |
|
|
|
|
using System.Text; |
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
using Google.Protobuf.Collections; |
|
|
|
|
using Microsoft.AspNetCore.Mvc.ModelBinding; |
|
|
|
|
using NPOI.HSSF.UserModel; |
|
|
|
|
using NPOI.OpenXmlFormats.Spreadsheet; |
|
|
|
|
using NPOI.SS.UserModel; |
|
|
|
@ -108,12 +109,19 @@ public static class ReportHelper |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static async Task<long> ExportExcel(ISqlSugarClient Db, List<QueryExportColumn> tableColumn, DataTable dt) |
|
|
|
|
public static async Task<long> ImportTemplate(ISqlSugarClient Db, List<QueryExportColumn> tableColumn, DataTable dt, string menuName) |
|
|
|
|
{ |
|
|
|
|
string filepath = ""; |
|
|
|
|
|
|
|
|
|
//生成表格 |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
//生成文件至文件服务器 |
|
|
|
|
var fid = SnowFlakeSingle.Instance.NextId(); |
|
|
|
|
var filepath = $"{$"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}wwwroot{Path.DirectorySeparatorChar}files{Path.DirectorySeparatorChar}import{Path.DirectorySeparatorChar}{fid}{Path.DirectorySeparatorChar}"}"; |
|
|
|
|
if (!Directory.Exists(filepath)) |
|
|
|
|
Directory.CreateDirectory(filepath); |
|
|
|
|
var fname = $"{menuName}.xlsx"; |
|
|
|
|
IWorkbook fileWorkbook; |
|
|
|
|
bool IsHSSF = true; |
|
|
|
|
if (Path.GetExtension(filepath) == ".xls") |
|
|
|
@ -163,7 +171,7 @@ public static class ReportHelper |
|
|
|
|
ICell cell = erow_1.CreateCell(SortNum); |
|
|
|
|
ICell cel2 = erow_2.CreateCell(SortNum); |
|
|
|
|
string field = drow.field; |
|
|
|
|
; |
|
|
|
|
; |
|
|
|
|
string label = drow.label; |
|
|
|
|
// 批注 |
|
|
|
|
string commentText = string.Empty; |
|
|
|
@ -277,10 +285,12 @@ public static class ReportHelper |
|
|
|
|
for (int i = 0; i < dt.Rows.Count; i++) |
|
|
|
|
{ |
|
|
|
|
IRow row1 = sheet.CreateRow(i + 2); |
|
|
|
|
for (int j = 0; j < dt.Columns.Count; j++) |
|
|
|
|
ICell cell = row1.CreateCell(0); |
|
|
|
|
cell.SetCellValue(i + 1); |
|
|
|
|
for (int j = 1; j <= tableColumn.Count; j++) |
|
|
|
|
{ |
|
|
|
|
ICell cell = row1.CreateCell(j); |
|
|
|
|
cell.SetCellValue(dt.Rows[i][j].ToString()); |
|
|
|
|
cell = row1.CreateCell(j); |
|
|
|
|
cell.SetCellValue(dt.Rows[i][tableColumn[j - 1].field].ToString()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -344,7 +354,7 @@ public static class ReportHelper |
|
|
|
|
var buf = stream.ToArray(); |
|
|
|
|
|
|
|
|
|
//保存为Excel文件 |
|
|
|
|
using (FileStream fs = new FileStream(filepath, FileMode.Create, FileAccess.Write)) |
|
|
|
|
using (FileStream fs = new FileStream(filepath + fname, FileMode.Create, FileAccess.Write)) |
|
|
|
|
{ |
|
|
|
|
fs.Write(buf, 0, buf.Length); |
|
|
|
|
fs.Flush(); |
|
|
|
|