update 20240925
This commit is contained in:
100
DOCGEN/Klassen/SyncFExcel.cs
Normal file
100
DOCGEN/Klassen/SyncFExcel.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Model;
|
||||
using Syncfusion.DocIO.DLS;
|
||||
using Syncfusion.XlsIO;
|
||||
|
||||
namespace DOCGEN.Klassen
|
||||
{
|
||||
public class SyncFExcel
|
||||
{
|
||||
public bool create_nativ(string property, string value, string base64, string originalfile, string destfile)
|
||||
{
|
||||
FileStream ms = new FileStream(originalfile, FileMode.Open, FileAccess.Read);
|
||||
FileStream os = new FileStream(destfile, FileMode.Create);
|
||||
ExcelEngine ex = new ExcelEngine();
|
||||
IApplication application = ex.Excel;
|
||||
IWorkbook workbook = application.Workbooks.Open(ms);
|
||||
|
||||
try
|
||||
{
|
||||
workbook.CustomDocumentProperties[property].Text = value;
|
||||
}
|
||||
catch
|
||||
{
|
||||
workbook.CustomDocumentProperties.Remove(property);
|
||||
workbook.CustomDocumentProperties[property].Text = value;
|
||||
|
||||
}
|
||||
workbook.Replace("{" + property + "}", value);
|
||||
//workbook.Names[workbook.CustomDocumentProperties[property].Name].RefersToRange.Text= workbook.CustomDocumentProperties[property].Text;
|
||||
workbook.SaveAs(os);
|
||||
workbook.Close();
|
||||
workbook = null;
|
||||
application = null;
|
||||
ms.Close();
|
||||
ms.Dispose();
|
||||
os.Close();
|
||||
os.Dispose();
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public string Generate_Excel(string base64, clsDocData docdata)
|
||||
{
|
||||
ExcelEngine ex = new ExcelEngine();
|
||||
IApplication app = ex.Excel;
|
||||
MemoryStream ms = new MemoryStream(Helper.EncodeExtensions.DecodeBase642ByteArray(base64));
|
||||
IWorkbook workBook = app.Workbooks.Open(ms, ExcelOpenType.Automatic);
|
||||
|
||||
string formattype = "";
|
||||
|
||||
foreach (clsDocValue dv in docdata.DocValues)
|
||||
{
|
||||
foreach (IWorksheet worksheet in workBook.Worksheets)
|
||||
{
|
||||
if (dv.FieldName== "TGEDKNameInhaber")
|
||||
{
|
||||
var a = 0;
|
||||
}
|
||||
try
|
||||
{
|
||||
worksheet.Range[dv.FieldName].Text = dv.Value.ToString();
|
||||
}
|
||||
catch { }
|
||||
|
||||
//foreach (IName name in worksheet.Names)
|
||||
//{
|
||||
|
||||
// name.Value = dv.Value.ToString();
|
||||
// Debug.Print(name.Value);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
MemoryStream destms = new MemoryStream();
|
||||
workBook.SaveAs(destms);
|
||||
workBook.Close();
|
||||
workBook = null;
|
||||
ex.Dispose();
|
||||
|
||||
byte[] imageArray = destms.ToArray();
|
||||
|
||||
if (docdata.Result_as_PDF == "True")
|
||||
{
|
||||
DocGet getdoc = new DocGet("");
|
||||
string destdoc = "";
|
||||
destdoc = getdoc.Convert_Word_To_PDF(Convert.ToBase64String(imageArray));
|
||||
return destdoc;
|
||||
}
|
||||
|
||||
return Convert.ToBase64String(imageArray);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user