You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
238 lines
8.7 KiB
238 lines
8.7 KiB
using System;
|
|
using System.Buffers.Text;
|
|
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;
|
|
using Syncfusion.XlsIO.Implementation.XmlSerialization;
|
|
|
|
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, string apptype)
|
|
{
|
|
ExcelEngine ex = new ExcelEngine();
|
|
IApplication app = ex.Excel;
|
|
MemoryStream ms = new MemoryStream(Helper.EncodeExtensions.DecodeBase642ByteArray(base64));
|
|
IWorkbook workBook = app.Workbooks.Open(ms, ExcelOpenType.Automatic);
|
|
|
|
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);
|
|
//}
|
|
}
|
|
|
|
}
|
|
if (docdata.Barcode == true)
|
|
{
|
|
Insert_Barcode(workBook, docdata);
|
|
}
|
|
|
|
MemoryStream destms = new MemoryStream();
|
|
if (apptype == "XLTM")
|
|
{
|
|
workBook.SaveAs(destms, ExcelSaveType.SaveAsMacroTemplate);
|
|
} else
|
|
{
|
|
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);
|
|
|
|
}
|
|
|
|
public void get_values(ref System.Data.DataTable dt, string excelfile)
|
|
{
|
|
ExcelEngine ex = new ExcelEngine();
|
|
IApplication app = ex.Excel;
|
|
MemoryStream ms = new MemoryStream(Helper.EncodeExtensions.DecodeBase642ByteArray(excelfile));
|
|
IWorkbook workBook = app.Workbooks.Open(ms, ExcelOpenType.Automatic);
|
|
foreach (System.Data.DataRow dr in dt.Rows)
|
|
{
|
|
int row = 0;
|
|
int col = 0;
|
|
row = Convert.ToInt32(dr["rowindex"]);
|
|
col = Convert.ToInt32(dr["columnindex"]);
|
|
|
|
string value = workBook.Worksheets[Convert.ToInt32(dr["sheet"]) - 1].Range[row, col].DisplayText.ToString();
|
|
dr["value"] = value;
|
|
}
|
|
workBook.Close();
|
|
workBook = null;
|
|
ex.Dispose();
|
|
|
|
}
|
|
public void Insert_Barcode(IWorkbook workBook, clsDocData docData)
|
|
{
|
|
System.Drawing.Image barcodeimage;
|
|
BarcodeLib.Barcode Barcode = new BarcodeLib.Barcode();
|
|
switch (docData.barcode_type)
|
|
{
|
|
case "0":
|
|
int rotation = 0;
|
|
if (docData.barcode_horizontal == 0) { rotation = 270; }
|
|
barcodeimage = Barcode.Get_LinerBarcode(Barcoded.Symbology.I2of5, docData.Dokumentid.Substring(6, 16), docData.Dokumentid.Substring(6, 16) + docData.barcode_zusatz, docData.barcode_textposition, docData.Zusatz_Font, Convert.ToInt32(docData.Zusatz_FontSize), rotation);
|
|
break;
|
|
case "1":
|
|
|
|
//barcodeimage = Barcode.Get_Datamatrix(DataMatrix.net.DmtxScheme.DmtxSchemeAutoBest, docData.barcode_content, 4, 0, 0, "Left", docData.barcode_content, docData.barcode_font, docData.barcode_fontsize);
|
|
|
|
barcodeimage = Barcode.Get_Datamatrix(DataMatrix.net.DmtxScheme.DmtxSchemeAscii, docData.barcode_content, 6, 6, 0, "Right", docData.barcode_text + docData.barcode_zusatz, docData.barcode_font, docData.barcode_fontsize + 5);
|
|
//barcodeimage.Save(@"x:\bctest.png");
|
|
break;
|
|
default:
|
|
barcodeimage = Barcode.Get_LinerBarcode(Barcoded.Symbology.I2of5C, docData.Dokumentid.Substring(9, 13), docData.Dokumentid.Substring(6, 16) + docData.barcode_zusatz, docData.barcode_textposition, docData.barcode_font, Convert.ToInt32(docData.barcode_fontsize), 0);
|
|
break;
|
|
}
|
|
foreach (IWorksheet worksheet in workBook.Worksheets)
|
|
{
|
|
foreach (IName name in workBook.Names)
|
|
{
|
|
if (name.Name.ToString().ToUpper().Contains("TGEDKBC"))
|
|
{
|
|
|
|
int i = name.Index;
|
|
int row = worksheet.Range[name.Name].Row;
|
|
int col = worksheet.Range[name.Name].Column;
|
|
|
|
string barcode = Bar25I(docData.Dokumentid.Substring(6, 16));
|
|
worksheet.Range[name.Name].Value= barcode;
|
|
//worksheet.Range[dv.FieldName].Text = dv.Value.ToString();
|
|
//IPictureShape picture = worksheet.Pictures.AddPicture(row, col, barcodeimage);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
// System.Drawing.Im
|
|
}
|
|
|
|
public bool IsNumeric(string value)
|
|
{
|
|
return value.All(char.IsNumber);
|
|
}
|
|
public string Bar25I(string BarTextIn)
|
|
{
|
|
string Bar25IRet = default;
|
|
string BarTextOut = "";
|
|
string TempString = "";
|
|
long CharValue = 0;
|
|
string barcodeout = "";
|
|
// Initialize input and output strings
|
|
BarTextOut = "";
|
|
BarTextIn = BarTextIn.Trim();
|
|
|
|
// Throw away non-numeric data
|
|
TempString = "";
|
|
for (int II = 1, loopTo = BarTextIn.Length; II <= loopTo; II++)
|
|
{
|
|
if (IsNumeric(BarTextIn.Substring(II - 1, 1)))
|
|
{
|
|
TempString = TempString + BarTextIn.Substring(II - 1, 1);
|
|
}
|
|
}
|
|
|
|
// If not an even number of digits, add a leading 0
|
|
if (TempString.Length % 2 == 1)
|
|
{
|
|
TempString = "0" + TempString;
|
|
}
|
|
|
|
// Break digit pairs up and convert to characters- build output string
|
|
for (int II = 1, loopTo1 = TempString.Length; II <= loopTo1; II += 2)
|
|
{
|
|
// Break string into pairs of digits and get value
|
|
CharValue = Convert.ToInt32(TempString.Substring(II - 1, 2));
|
|
// translate value to ASCII and save in BarTextOut
|
|
if (CharValue < 90)
|
|
{
|
|
BarTextOut = BarTextOut + (char)(CharValue + 33);
|
|
}
|
|
else
|
|
{
|
|
BarTextOut = BarTextOut + (char)(CharValue + 71);
|
|
}
|
|
}
|
|
|
|
// Build ouput string, trailing space for Windows rasterization bug
|
|
barcodeout = "{" + BarTextOut + "} ";
|
|
|
|
// Return the string
|
|
Bar25IRet = barcodeout;
|
|
return Bar25IRet;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|