|
@@ -1,5 +1,8 @@
|
|
|
-using Aspose.Words;
|
|
|
+using Aspose.Cells;
|
|
|
+using Aspose.Words;
|
|
|
+using System.Collections.Generic;
|
|
|
using System.Data;
|
|
|
+using System.IO;
|
|
|
using System.Web;
|
|
|
using Ubiety.Dns.Core;
|
|
|
|
|
@@ -16,12 +19,13 @@ namespace OASystem.API.OAMethodLib.File
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
- public static string ExpertWordToModel(string tempPath, string outputFileName, Dictionary<string,object> dic, List<DataTable>? listDt)
|
|
|
+ public static string ExpertWordToModel(string tempFileName, string saveFolderName, string saveFilName, Dictionary<string,object> dic,
|
|
|
+ List<DataTable>? listDt)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
@@ -36,6 +40,7 @@ namespace OASystem.API.OAMethodLib.File
|
|
|
fieldValues.Add(dic[key]);
|
|
|
}
|
|
|
|
|
|
+ string tempPath = string.Format("{0}/Word/Template/{1}", AppSettingsHelper.Get("OfficeTempBasePath"), tempFileName);
|
|
|
|
|
|
Document doc = new Document(tempPath);
|
|
|
doc.MailMerge.Execute(fieldNames.ToArray(), fieldValues.ToArray());
|
|
@@ -53,15 +58,24 @@ namespace OASystem.API.OAMethodLib.File
|
|
|
|
|
|
|
|
|
doc.MailMerge.Execute(new[] { "PageCount" }, new object[] { doc.PageCount });
|
|
|
-
|
|
|
|
|
|
- string outputPath = string.Format("C:\\Server\\File\\OA2023\\Office\\Word\\TencentOCR\\Save\\{0}", outputFileName);
|
|
|
- doc.Save(outputPath);
|
|
|
- return outputPath;
|
|
|
+ string path = string.Format("{0}/Word/{1}", AppSettingsHelper.Get("OfficeTempBasePath"), saveFolderName);
|
|
|
+
|
|
|
+ if (!System.IO.Directory.Exists(path))
|
|
|
+ {
|
|
|
+ System.IO.Directory.CreateDirectory(path);
|
|
|
+ }
|
|
|
+
|
|
|
+ string saveFilePath = string.Format("{0}{1}", path, saveFilName);
|
|
|
+
|
|
|
+
|
|
|
+ doc.Save(saveFilePath);
|
|
|
+ saveFilePath = saveFilePath.Replace("C:", AppSettingsHelper.Get("OfficeBaseUrl"));
|
|
|
+ return saveFilePath;
|
|
|
}
|
|
|
- catch (Exception er)
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- return er.Message;
|
|
|
+ return ex.Message;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -78,50 +92,65 @@ namespace OASystem.API.OAMethodLib.File
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
- public static string ExpertExcelToModel(string tempPath, string outputFileName, Dictionary<string, object> dic, List<DataTable>? listDt)
|
|
|
+ public static string ExpertExcelToModel(string tempFileName, string saveFolderName, string saveFilName, Dictionary<string, object> dic,
|
|
|
+ List<DataTable>? listDt)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- removeWatermark();
|
|
|
-
|
|
|
- List<string> fieldNames = new List<string>();
|
|
|
- List<object> fieldValues = new List<object>();
|
|
|
-
|
|
|
- foreach (string key in dic.Keys)
|
|
|
- {
|
|
|
- fieldNames.Add(key);
|
|
|
- fieldValues.Add(dic[key]);
|
|
|
- }
|
|
|
+ string tempPath = string.Format("{0}/Excel/Template/{1}",AppSettingsHelper.Get("OfficeTempBasePath"), tempFileName);
|
|
|
|
|
|
|
|
|
- Document doc = new Document(tempPath);
|
|
|
- doc.MailMerge.Execute(fieldNames.ToArray(), fieldValues.ToArray());
|
|
|
-
|
|
|
+ Workbook wbook = new Workbook(tempPath);
|
|
|
+
|
|
|
+ Worksheet wSheet = wbook.Worksheets[0];
|
|
|
+ WorkbookDesigner designer = new WorkbookDesigner(wbook);
|
|
|
+
|
|
|
+
|
|
|
if (listDt != null && listDt.Count > 0)
|
|
|
{
|
|
|
- foreach (DataTable dt in listDt)
|
|
|
+ foreach (var item in listDt)
|
|
|
{
|
|
|
- if (dt != null && dt.Rows.Count > 0)
|
|
|
+ if (item.Rows.Count > 0)
|
|
|
{
|
|
|
- doc.MailMerge.ExecuteWithRegions(dt);
|
|
|
+ designer.SetDataSource(item.TableName, item);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- doc.MailMerge.Execute(new[] { "PageCount" }, new object[] { doc.PageCount });
|
|
|
-
|
|
|
- doc.Save(outputPath);
|
|
|
- return outputPath;
|
|
|
+
|
|
|
+ if (dic.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var item in dic)
|
|
|
+ {
|
|
|
+ designer.SetDataSource(item.Key, item.Value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ designer.Process();
|
|
|
+
|
|
|
+ string path = string.Format("{0}/Excel/{1}", AppSettingsHelper.Get("OfficeTempBasePath"), saveFolderName);
|
|
|
+
|
|
|
+ if (!System.IO.Directory.Exists(path))
|
|
|
+ {
|
|
|
+ System.IO.Directory.CreateDirectory(path);
|
|
|
+ }
|
|
|
+
|
|
|
+ string saveFilePath = string.Format("{0}{1}", path, saveFilName);
|
|
|
+
|
|
|
+
|
|
|
+ wbook.Save(saveFilePath, Aspose.Cells.SaveFormat.Xlsx);
|
|
|
+ saveFilePath = saveFilePath.Replace("C:", AppSettingsHelper.Get("OfficeBaseUrl"));
|
|
|
+ return saveFilePath;
|
|
|
}
|
|
|
- catch (Exception er)
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- return er.Message;
|
|
|
+ return ex.Message;
|
|
|
}
|
|
|
}
|
|
|
|