|
|
using Microsoft.Office.Interop.Excel;
|
|
|
using Microsoft.Office.Interop.Word;
|
|
|
using Model;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Data;
|
|
|
using System.Linq;
|
|
|
using System.Linq.Expressions;
|
|
|
using System.Runtime.InteropServices;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using Microsoft.Office;
|
|
|
using System.Threading;
|
|
|
using System.Drawing;
|
|
|
using Font = System.Drawing.Font;
|
|
|
using System.Xml.Linq;
|
|
|
using BarcodeLib;
|
|
|
using System.Drawing.Drawing2D;
|
|
|
using Syncfusion.DocIO;
|
|
|
using Syncfusion.DocIO.DLS;
|
|
|
using System.IO;
|
|
|
using Microsoft.VisualBasic;
|
|
|
using System.Net.NetworkInformation;
|
|
|
using System.Net;
|
|
|
using Microsoft.VisualBasic.CompilerServices;
|
|
|
using Database;
|
|
|
using System.Runtime.InteropServices.ComTypes;
|
|
|
using Syncfusion.CompoundFile.DocIO;
|
|
|
using Helper;
|
|
|
using Microsoft.VisualBasic.Logging;
|
|
|
using System.Data.Common;
|
|
|
using static System.Net.WebRequestMethods;
|
|
|
|
|
|
|
|
|
|
|
|
namespace OnDocOffice
|
|
|
{
|
|
|
public class clsExcelEdit
|
|
|
{
|
|
|
public string connectstring { get; set; }
|
|
|
public string filename { get; set; }
|
|
|
public string dokumentid { get; set; }
|
|
|
public
|
|
|
Microsoft.Office.Interop.Excel.Application excel;
|
|
|
Workbook workBook = null;
|
|
|
|
|
|
public string resturi = "";
|
|
|
public string apikey = "";
|
|
|
|
|
|
public clsExcelEdit(string connectstring, string filename, string dokumentid)
|
|
|
{
|
|
|
this.connectstring = connectstring;
|
|
|
this.filename = filename;
|
|
|
this.dokumentid = dokumentid;
|
|
|
|
|
|
}
|
|
|
|
|
|
public bool Start_Application()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
excel = new Microsoft.Office.Interop.Excel.Application();
|
|
|
return true;
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void Edit_Document(bool runmacros)
|
|
|
{
|
|
|
Start_Application();
|
|
|
workBook = excel.Workbooks.Open(filename);
|
|
|
excel.Visible = true;
|
|
|
if (runmacros == true)
|
|
|
{
|
|
|
Logging.Logging.Debug("Makros auslesen", "Edit_Document", dokumentid);
|
|
|
Database.DB db = new Database.DB(connectstring);
|
|
|
db.Get_Tabledata("Select * from ondoc_macros where dokumentid='" + dokumentid + "' order by reihenfolge", false, true);
|
|
|
foreach (DataRow dr in db.dsdaten.Tables[0].Rows)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
Logging.Logging.Debug("Makro ", "Edit_Document", dr[0].ToString());
|
|
|
excel.Run(dr[0].ToString());
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
Logging.Logging.Debug("MakroError ", "Edit_Document", e.Message);
|
|
|
string a = e.Message;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//clsProcessWatch.AddToList(dokumentid, filename, "Word");
|
|
|
bool isClosed = IsDocumentClosed(excel, workBook);
|
|
|
workBook = null;
|
|
|
excel = null;
|
|
|
}
|
|
|
|
|
|
public void Control_Word(string dokumentid, string filename, string application)
|
|
|
{
|
|
|
//clsProcessWatch.AddToList(dokumentid, filename, application);
|
|
|
}
|
|
|
|
|
|
static bool IsDocumentClosed(Microsoft.Office.Interop.Excel.Application excelApp, Workbook workBook)
|
|
|
{
|
|
|
// Check if the document is still listed in the Documents collection
|
|
|
foreach (Workbook openDoc in excelApp.Workbooks)
|
|
|
{
|
|
|
if (openDoc.FullName == workBook.FullName)
|
|
|
{
|
|
|
return false; // Document is still open
|
|
|
}
|
|
|
}
|
|
|
return true; // Document is closed
|
|
|
}
|
|
|
|
|
|
public void run_macros()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
public string convert_excel(string x)
|
|
|
{
|
|
|
string s;
|
|
|
string s1;
|
|
|
int i;
|
|
|
s = x;
|
|
|
i = Microsoft.VisualBasic.Strings.InStr(s, Strings.Chr(13).ToString());
|
|
|
while (i > 0)
|
|
|
{
|
|
|
s = Strings.Left(s, i - 1) + "#" + Strings.Right(s, Strings.Len(s) - (i));
|
|
|
if (Strings.Mid(s, i + 1, 1) == Strings.Chr(10).ToString())
|
|
|
s = Strings.Left(s, i) + Strings.Right(s, Strings.Len(s) - (i + 1));
|
|
|
i = Microsoft.VisualBasic.Strings.InStr(s, Strings.Chr(13).ToString());
|
|
|
}
|
|
|
i = Microsoft.VisualBasic.Strings.InStr(s, "#");
|
|
|
while (i > 0)
|
|
|
{
|
|
|
s = Strings.Left(s, i - 1) + Strings.Chr(10) + Strings.Right(s, Strings.Len(s) - (i));
|
|
|
i = Microsoft.VisualBasic.Strings.InStr(s, "#");
|
|
|
}
|
|
|
return s;
|
|
|
}
|
|
|
public string Generate_Excel_in_Office(ref clsDocData docdata, ref clsdok dok, string vorlage, string connectionstring, string tempdir, string dokumentid, string apptype, string extension, int OfficeSleep, int bookmarks_docio)
|
|
|
{
|
|
|
this.connectstring = connectionstring;
|
|
|
this.dokumentid = docdata.Dokumentid;
|
|
|
string filename = tempdir + dokumentid + "." + extension;
|
|
|
filename = tempdir + docdata.prefix+dokumentid+"." + extension;
|
|
|
dok.dokumentname = docdata.prefix + dokumentid + "." + extension;
|
|
|
bool cursor = false;
|
|
|
int sheetcursor = 0;
|
|
|
int i = 0;
|
|
|
Helper.clsFileHelper fh = new Helper.clsFileHelper();
|
|
|
fh.SaveBase64ToFile(vorlage, filename);
|
|
|
Start_Application();
|
|
|
workBook = excel.Workbooks.Add(filename);
|
|
|
//workBook = excel.Workbooks.Open(filename);
|
|
|
foreach (Worksheet ws in workBook.Sheets)
|
|
|
{
|
|
|
ws.Activate();
|
|
|
foreach (clsDocValue dv in docdata.DocValues)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
Logging.Logging.Debug("Excel: "+dv.FieldName+" / "+dv.Value,"OnDocOffice","");
|
|
|
if (dv.TMBeginn == "TGEDKCursor" || dv.TMBeginn == "TGEDKCursorB" || dv.FieldName == "TGEDKCursor" || dv.FieldName == "TGEDKCursorB")
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
excel.Range[workBook.Names.Item(dv.FieldName).NameLocal].Select();
|
|
|
cursor = true;
|
|
|
sheetcursor = i;
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
excel.Range[workBook.Names.Item(dv.FieldName).NameLocal].Select();
|
|
|
excel.ActiveCell.FormulaR1C1 = convert_excel(dv.Value);
|
|
|
}
|
|
|
}
|
|
|
catch { }
|
|
|
}
|
|
|
i = i + 1;
|
|
|
}
|
|
|
if (docdata.Barcode == true)
|
|
|
{
|
|
|
string barcode = Bar25I(dokumentid.Substring(6, 16));
|
|
|
foreach (Worksheet ws in workBook.Sheets)
|
|
|
{
|
|
|
ws.Activate();
|
|
|
int i1 = 0;
|
|
|
int i2 = 0;
|
|
|
for (i1 = 1; i1 < workBook.Names.Count; i1++)
|
|
|
{
|
|
|
|
|
|
string na = workBook.Names.Item(i1).NameLocal;
|
|
|
if (na.Substring(0, 7) == "TGEDKBC")
|
|
|
{
|
|
|
excel.Range[excel.Names.Item(na).NameLocal].Select();
|
|
|
excel.ActiveCell.FormulaR1C1 = barcode;
|
|
|
try
|
|
|
{
|
|
|
excel.Selection.Characters.Font.Name = docdata.barcode_font;
|
|
|
}
|
|
|
catch { }
|
|
|
}
|
|
|
if (na.Substring(0, 7) == "TGEDKAR")
|
|
|
{
|
|
|
excel.Range[excel.Names.Item(na).NameLocal].Select();
|
|
|
excel.ActiveCell.FormulaR1C1 = convert_excel(docdata.barcode_zusatz);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Database.DB db = new Database.DB(connectstring);
|
|
|
db.Get_Tabledata("Select * from ondoc_macros where dokumentid='" + dokumentid + "' order by reihenfolge", false, true);
|
|
|
foreach (DataRow dr in db.dsdaten.Tables[0].Rows)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
Logging.Logging.Debug("Makro ", "Create", dr[0].ToString());
|
|
|
excel.Run(dr[0].ToString());
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
Logging.Logging.Debug("MakroError ", "Create", e.Message);
|
|
|
string a = e.Message;
|
|
|
}
|
|
|
}
|
|
|
db = null;
|
|
|
|
|
|
workBook.Save();
|
|
|
workBook.Close();
|
|
|
workBook = null;
|
|
|
|
|
|
string b64 = fh.Base64FromFile(filename);
|
|
|
excel.Workbooks.Open(filename);
|
|
|
excel.Visible = true;
|
|
|
excel = null;
|
|
|
Logging.Logging.Debug("Generierung abgeschlossen", "clsOffice", dokumentid);
|
|
|
return b64;
|
|
|
//return fh.Base64FromFile(filename);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public class clsWordEdit
|
|
|
{
|
|
|
public string connectstring { get; set; }
|
|
|
public string filename { get; set; }
|
|
|
public string dokumentid { get; set; }
|
|
|
|
|
|
public string cursortm { get; set; }
|
|
|
public string cursorfeld { get; set; }
|
|
|
|
|
|
public bool is_protected { get; set; } = false;
|
|
|
public
|
|
|
Microsoft.Office.Interop.Word.Application word;
|
|
|
Microsoft.Office.Interop.Word.Document worddoc;
|
|
|
Document doc = null;
|
|
|
|
|
|
public string resturi = "";
|
|
|
public string apikey = "";
|
|
|
|
|
|
|
|
|
public clsWordEdit(string connectstring, string filename, string dokumentid, string resturi, string apikey)
|
|
|
{
|
|
|
this.connectstring = connectstring;
|
|
|
this.filename = filename;
|
|
|
this.dokumentid = dokumentid;
|
|
|
this.resturi = resturi;
|
|
|
this.apikey = apikey;
|
|
|
}
|
|
|
public bool Start_Application()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
//Type WordType = Type.GetTypeFromProgID("Word.Application");
|
|
|
//word = Activator.CreateInstance(WordType);
|
|
|
////ExcelInst.Visible = true;
|
|
|
|
|
|
word = (Microsoft.Office.Interop.Word.Application)Interaction.CreateObject("Word.Application");
|
|
|
//word = new Microsoft.Office.Interop.Word.Application();
|
|
|
word.Run("Autoexec");
|
|
|
word.NormalTemplate.Saved = true;
|
|
|
return true;
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public void Edit_Document(bool runmacros)
|
|
|
{
|
|
|
Start_Application();
|
|
|
doc = word.Documents.Open(filename);
|
|
|
|
|
|
word.Visible = true;
|
|
|
|
|
|
if (runmacros == true)
|
|
|
{
|
|
|
Logging.Logging.Debug("Makros auslesen", "Edit_Document", dokumentid);
|
|
|
Database.DB db = new Database.DB(connectstring);
|
|
|
db.Get_Tabledata("Select * from ondoc_macros where dokumentid='" + dokumentid + "' order by reihenfolge", false, true);
|
|
|
foreach (DataRow dr in db.dsdaten.Tables[0].Rows)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
Logging.Logging.Debug("Makro ", "Edit_Document", dr[0].ToString());
|
|
|
word.Run(dr[0].ToString());
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
Logging.Logging.Debug("MakroError ", "Edit_Document", e.Message);
|
|
|
string a = e.Message;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//clsProcessWatch.AddToList(dokumentid, filename, "Word");
|
|
|
bool isClosed = IsDocumentClosed(word, doc);
|
|
|
doc = null;
|
|
|
word = null;
|
|
|
}
|
|
|
|
|
|
public void Control_Word(string dokumentid, string filename, string application)
|
|
|
{
|
|
|
//clsProcessWatch.AddToList(dokumentid, filename, application);
|
|
|
}
|
|
|
|
|
|
static bool IsDocumentClosed(Microsoft.Office.Interop.Word.Application wordApp, Document doc)
|
|
|
{
|
|
|
// Check if the document is still listed in the Documents collection
|
|
|
try
|
|
|
{
|
|
|
foreach (Document openDoc in wordApp.Documents)
|
|
|
{
|
|
|
if (openDoc.FullName == doc.FullName)
|
|
|
{
|
|
|
return false; // Document is still open
|
|
|
}
|
|
|
}
|
|
|
return true; // Document is closed
|
|
|
}
|
|
|
catch { return true; }
|
|
|
}
|
|
|
|
|
|
public void run_macros(ref clsDocData docdata, string connectionstring)
|
|
|
{
|
|
|
Database.DB db = new Database.DB(connectionstring);
|
|
|
db.Get_Tabledata("select * from view_idv_makros where office_vorlagenr=" + docdata.VorlageNr.ToString() + " order by reihenfolge asc", false, true);
|
|
|
if (db.dsdaten.Tables[0].Rows.Count > 0) { word.Visible = true; word.Activate(); }
|
|
|
foreach (DataRow dr in db.dsdaten.Tables[0].Rows)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
if (dr[0].ToString() == "DokumentSchuetzen")
|
|
|
{
|
|
|
worddoc.Range(0, 0).Select();
|
|
|
worddoc.Protect(Type: Microsoft.Office.Interop.Word.WdProtectionType.wdAllowOnlyFormFields, NoReset: true, Password: "Australia");
|
|
|
}
|
|
|
try
|
|
|
{
|
|
|
word.Run(dr[0].ToString());
|
|
|
}
|
|
|
catch (Exception e) { string a = e.Message; }
|
|
|
}
|
|
|
catch { }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void Word_Compatibility_Mode(ref WordDocument wd)
|
|
|
{
|
|
|
CompatibilityMode compatibilityMode = wd.Settings.CompatibilityMode;
|
|
|
var formattype_original = wd.ActualFormatType;
|
|
|
switch (compatibilityMode)
|
|
|
{
|
|
|
case CompatibilityMode.Word2010:
|
|
|
wd.Settings.CompatibilityMode = CompatibilityMode.Word2010;
|
|
|
break;
|
|
|
case CompatibilityMode.Word2013:
|
|
|
wd.Settings.CompatibilityMode = CompatibilityMode.Word2013;
|
|
|
break;
|
|
|
default:
|
|
|
// wd.Settings.CompatibilityMode = CompatibilityMode.Word2003;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
private void get_bookmakrs(string file, ref clsDocData ddata)
|
|
|
{
|
|
|
MemoryStream ms = new MemoryStream(Helper.EncodeExtensions.DecodeBase642ByteArray(file));
|
|
|
WordDocument document = new WordDocument(ms, FormatType.Automatic);
|
|
|
//List<Syncfusion.DocIO.DLS.Bookmark> bookmarks = new List<Syncfusion.DocIO.DLS.Bookmark>();
|
|
|
BookmarkCollection bookmarks = document.Bookmarks;
|
|
|
foreach (clsDocValue dv in ddata.DocValues)
|
|
|
|
|
|
{
|
|
|
dv.used = 0;
|
|
|
foreach (Syncfusion.DocIO.DLS.Bookmark bm in bookmarks)
|
|
|
{
|
|
|
if (bm.Name == dv.TMBeginn.ToString()) { dv.used = 1;break; }
|
|
|
//dv.used = 1;
|
|
|
//break;
|
|
|
}
|
|
|
}
|
|
|
//foreach (Syncfusion.DocIO.DLS.Bookmark bm in bookmarks)
|
|
|
//{
|
|
|
// foreach (clsDocValue dv in ddata.DocValues)
|
|
|
// {
|
|
|
// if (dv.TMBeginn==bm.Name || dv.TMEnd == bm.Name)
|
|
|
// {
|
|
|
// dv.used = 1;
|
|
|
// } else { dv.used = 0; }
|
|
|
// }
|
|
|
//}
|
|
|
ms = null;
|
|
|
}
|
|
|
private string set_cmode(string file)
|
|
|
{
|
|
|
string formattype = "";
|
|
|
MemoryStream ms = new MemoryStream(Helper.EncodeExtensions.DecodeBase642ByteArray(file));
|
|
|
WordDocument document = new WordDocument(ms, FormatType.Automatic);
|
|
|
CompatibilityMode compatibilityMode = document.Settings.CompatibilityMode;
|
|
|
formattype = document.ActualFormatType.ToString();
|
|
|
var formattype_original = document.ActualFormatType;
|
|
|
Word_Compatibility_Mode(ref document);
|
|
|
//switch (compatibilityMode)
|
|
|
//{
|
|
|
// case CompatibilityMode.Word2010:
|
|
|
// document.Settings.CompatibilityMode = CompatibilityMode.Word2010;
|
|
|
// break;
|
|
|
// case CompatibilityMode.Word2013:
|
|
|
// document.Settings.CompatibilityMode = CompatibilityMode.Word2010;
|
|
|
// break;
|
|
|
// default:
|
|
|
// document.Settings.CompatibilityMode = CompatibilityMode.Word2003;
|
|
|
// break;
|
|
|
//}
|
|
|
MemoryStream destms = new MemoryStream();
|
|
|
document.Save(destms, formattype_original);
|
|
|
|
|
|
document.Close();
|
|
|
document.Dispose();
|
|
|
byte[] imageArray = destms.ToArray();
|
|
|
|
|
|
return Convert.ToBase64String(imageArray);
|
|
|
}
|
|
|
|
|
|
public string convert_wordfelder(string x)
|
|
|
{
|
|
|
|
|
|
string convert_wordfelderRet = default;
|
|
|
|
|
|
|
|
|
string s;
|
|
|
string s1;
|
|
|
int i;
|
|
|
s = x;
|
|
|
i = Strings.InStr(s, Conversions.ToString('\r'));
|
|
|
while (i > 0)
|
|
|
{
|
|
|
s = Strings.Left(s, i - 1) + "#" + Strings.Right(s, Strings.Len(s) - i);
|
|
|
if (Strings.Mid(s, i + 1, 1) == Conversions.ToString('\n'))
|
|
|
{
|
|
|
s = Strings.Left(s, i) + Strings.Right(s, Strings.Len(s) - (i + 1));
|
|
|
}
|
|
|
i = Strings.InStr(s, Conversions.ToString('\r'));
|
|
|
}
|
|
|
i = Strings.InStr(s, "#");
|
|
|
while (i > 0)
|
|
|
{
|
|
|
s = Strings.Left(s, i - 1) + '\v' + Strings.Right(s, Strings.Len(s) - i);
|
|
|
i = Strings.InStr(s, "#");
|
|
|
}
|
|
|
convert_wordfelderRet = s;
|
|
|
return convert_wordfelderRet;
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
public string Generate_Word_in_Office(ref clsDocData docdata, ref clsdok dok, string vorlage, string connectionstring, string tempdir, string dokumentid, string apptype, string extension, int OfficeSleep, int bookmarks_docio, bool vbfilemanagment, bool editdoc)
|
|
|
{
|
|
|
connectstring = connectionstring;
|
|
|
DialogGenerate dialogGenerate = new DialogGenerate(docdata.Bezeichnung.ToString());
|
|
|
dialogGenerate.Show();
|
|
|
System.Windows.Forms.Application.DoEvents();
|
|
|
dialogGenerate.set_progress(10,"Datei bereit stellen");
|
|
|
|
|
|
this.dokumentid = docdata.Dokumentid;
|
|
|
string filename = tempdir + docdata.prefix+dokumentid + "." + extension;
|
|
|
dok.dokumentname = docdata.prefix + dokumentid + "." + extension;
|
|
|
int pos = 0;
|
|
|
int pos2 = 0;
|
|
|
|
|
|
if (vbfilemanagment)
|
|
|
{
|
|
|
VBFileManagement.VBFileManagement vb = new VBFileManagement.VBFileManagement();
|
|
|
vb.Get_From_DB(Convert.ToInt32(docdata.VorlageNr), filename, connectionstring, false);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
}
|
|
|
Helper.clsFileHelper fh = new Helper.clsFileHelper();
|
|
|
|
|
|
//vorlage = fh.Base64FromFile(filename);
|
|
|
//vorlage = set_cmode(vorlage);
|
|
|
|
|
|
fh.SaveBase64ToFile(vorlage, filename);
|
|
|
get_bookmakrs(fh.Base64FromFile(filename), ref docdata);
|
|
|
Logging.Logging.Debug("Generate_Word_in_Office", "clsOffice", dokumentid);
|
|
|
dialogGenerate.set_progress(20,"Datei öffnen");
|
|
|
Start_Application();
|
|
|
|
|
|
// Thread.Sleep(OfficeSleep);
|
|
|
worddoc = word.Documents.Open(filename);
|
|
|
Thread.Sleep(OfficeSleep);
|
|
|
string ext = System.IO.Path.GetExtension(filename).ToUpper();
|
|
|
Logging.Logging.Debug(word.ActiveDocument.CompatibilityMode.ToString(), ext, dokumentid);
|
|
|
//switch (word.ActiveDocument.CompatibilityMode)
|
|
|
//{
|
|
|
// case 11: //word 2003
|
|
|
// word.ActiveDocument.SaveAs2(filename, CompatibilityMode.Word2010);
|
|
|
// break;
|
|
|
// case 12: //word 2007
|
|
|
// word.ActiveDocument.SaveAs2(filename, CompatibilityMode.Word2010);
|
|
|
// break;
|
|
|
// case 14: // word 2010
|
|
|
// word.ActiveDocument.SaveAs2(filename, CompatibilityMode.Word2010);
|
|
|
// break;
|
|
|
// default: //word 2013
|
|
|
// word.ActiveDocument.SaveAs2(filename);
|
|
|
// break;
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
int cmode = 0;
|
|
|
cmode = word.ActiveDocument.CompatibilityMode;
|
|
|
if (docdata.CompatibilityMode == "Word 2010") { cmode = 14; }
|
|
|
if (docdata.CompatibilityMode == "Word 2013") { cmode = 14; }
|
|
|
switch (cmode)
|
|
|
{
|
|
|
case 11:
|
|
|
case 12:
|
|
|
case 14:
|
|
|
switch (ext)
|
|
|
{
|
|
|
case ".DOCX":
|
|
|
word.ActiveDocument.SaveAs2(filename, CompatibilityMode: 14, FileFormat: Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXMLDocument);
|
|
|
break;
|
|
|
case ".DOCM":
|
|
|
word.ActiveDocument.SaveAs2(filename, CompatibilityMode: 14, FileFormat: Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXMLDocumentMacroEnabled);
|
|
|
break;
|
|
|
case ".DOTX":
|
|
|
word.ActiveDocument.SaveAs2(filename, FileFormat: Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXMLTemplate, CompatibilityMode: 14);
|
|
|
break;
|
|
|
case ".DOTM":
|
|
|
word.ActiveDocument.SaveAs2(filename, FileFormat: Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXMLTemplateMacroEnabled, CompatibilityMode: 14);
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
case 15:
|
|
|
case 16:
|
|
|
case 17:
|
|
|
case 18:
|
|
|
switch (ext)
|
|
|
{
|
|
|
case ".DOCX":
|
|
|
word.ActiveDocument.SaveAs2(filename, FileFormat: Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXMLDocument);
|
|
|
break;
|
|
|
case ".DOCM":
|
|
|
word.ActiveDocument.SaveAs2(filename, FileFormat: Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXMLDocumentMacroEnabled);
|
|
|
break;
|
|
|
case ".DOTX":
|
|
|
word.ActiveDocument.SaveAs2(filename, FileFormat: Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXMLTemplate);
|
|
|
break;
|
|
|
case ".DOTM":
|
|
|
word.ActiveDocument.SaveAs2(filename, FileFormat: Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXMLTemplateMacroEnabled);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
default:
|
|
|
switch (ext)
|
|
|
{
|
|
|
case ".DOCX":
|
|
|
word.ActiveDocument.SaveAs2(filename, CompatibilityMode: 11, FileFormat: Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXMLDocument);
|
|
|
break;
|
|
|
case ".DOCM":
|
|
|
word.ActiveDocument.SaveAs2(filename, CompatibilityMode: 11, FileFormat: Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXMLDocumentMacroEnabled);
|
|
|
break;
|
|
|
case ".DOTX":
|
|
|
word.ActiveDocument.SaveAs2(filename, FileFormat: Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXMLTemplate, CompatibilityMode: 11);
|
|
|
break;
|
|
|
case ".DOTM":
|
|
|
word.ActiveDocument.SaveAs2(filename, FileFormat: Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXMLTemplateMacroEnabled, CompatibilityMode: 11);
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
worddoc = word.ActiveDocument;
|
|
|
worddoc.Save();
|
|
|
word.NormalTemplate.Saved = true;
|
|
|
dialogGenerate.set_progress(30, "Datei konvertiert und geöffnet");
|
|
|
//word.ActiveDocument.Close(false);
|
|
|
Thread.Sleep(OfficeSleep);
|
|
|
//worddoc = word.Documents.Open(filename);
|
|
|
Logging.Logging.Debug("Word Open und Befüllen", "clsOffice", dokumentid);
|
|
|
Thread.Sleep(OfficeSleep);
|
|
|
if (worddoc.ProtectionType != Microsoft.Office.Interop.Word.WdProtectionType.wdNoProtection)
|
|
|
{
|
|
|
worddoc.Unprotect(Password: "Australia");
|
|
|
is_protected = true;
|
|
|
}
|
|
|
int usecount = 0;
|
|
|
Logging.Logging.Debug("VB Fill","OnDoc",dokumentid);
|
|
|
foreach (clsDocValue dv in docdata.DocValues)
|
|
|
{
|
|
|
//dv.used = 0;
|
|
|
if (dv.TMBeginn.Contains("CompanyBBEB99")) { dv.used = 1; };
|
|
|
if (dv.TMBeginn.Contains("EDKCursor"))
|
|
|
{
|
|
|
dv.used = 1;
|
|
|
cursortm = dv.TMBeginn;
|
|
|
}
|
|
|
if (dv.FieldName.Contains("TGEDKCursor"))
|
|
|
{
|
|
|
dv.used = 1;
|
|
|
cursorfeld = dv.FieldName;
|
|
|
}
|
|
|
|
|
|
|
|
|
if (dv.FieldName.ToString() != "") { dv.used = 1; };
|
|
|
if (dv.used == 1) { usecount++; }
|
|
|
|
|
|
}
|
|
|
float progressstep = 1;
|
|
|
try
|
|
|
{
|
|
|
float b = 50;
|
|
|
progressstep = b / (float)usecount;
|
|
|
progressstep = progressstep + 1;
|
|
|
}
|
|
|
catch
|
|
|
{ }
|
|
|
if (docdata.remove_signature)
|
|
|
{
|
|
|
word_signature ws = new word_signature(this.connectstring);
|
|
|
ws.remove_unterschriften(ref word, dokumentid);
|
|
|
ws = null;
|
|
|
}
|
|
|
|
|
|
VBOffice.VBOffice vbo = new VBOffice.VBOffice();
|
|
|
|
|
|
|
|
|
vbo.Fill_Word(ref word, ref docdata, editdoc, dialogGenerate,(float)progressstep);
|
|
|
vbo = null;
|
|
|
Logging.Logging.Debug("VB Fill Ende", "OnDoc", dokumentid);
|
|
|
|
|
|
if (docdata.sign == true)
|
|
|
{
|
|
|
string unterschriftlinks = "";
|
|
|
string unterschriftrechts = "";
|
|
|
string path_unterschriftlinks = "";
|
|
|
string path_unterschriftrechts = "";
|
|
|
if (docdata.Unterschrift_Links != "-1")
|
|
|
{
|
|
|
unterschriftlinks = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(get_unterschrift(docdata.Unterschrift_Links));
|
|
|
Helper.clsFileHelper clsFileHelper = new Helper.clsFileHelper();
|
|
|
path_unterschriftlinks = tempdir + dokumentid + "UL.png";
|
|
|
clsFileHelper.SaveBase64ToFile(unterschriftlinks, path_unterschriftlinks);
|
|
|
}
|
|
|
if (docdata.Unterschrift_Rechts != "-1")
|
|
|
{
|
|
|
unterschriftrechts = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(get_unterschrift(docdata.Unterschrift_Links));
|
|
|
Helper.clsFileHelper clsFileHelper = new Helper.clsFileHelper();
|
|
|
path_unterschriftrechts = tempdir + dokumentid + "UR.png";
|
|
|
clsFileHelper.SaveBase64ToFile(unterschriftrechts,path_unterschriftrechts);
|
|
|
}
|
|
|
word_signature word_Signature = new word_signature(connectionstring);
|
|
|
word_Signature.sign_doc(ref word, path_unterschriftlinks, path_unterschriftrechts, dokumentid, docdata.DokumenttypNr);
|
|
|
if (System.IO.File.Exists(path_unterschriftlinks)){ System.IO.File.Delete(tempdir + dokumentid + "UL.png"); };
|
|
|
if (System.IO.File.Exists(path_unterschriftrechts)){ System.IO.File.Delete(tempdir + dokumentid + "UR.png"); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
bool cursorpositionieren = false;
|
|
|
//if (docdata.Kopfzeile_generieren == true)
|
|
|
//{
|
|
|
// Kopfzeile_generieren();
|
|
|
//}
|
|
|
////word.Visible = false;
|
|
|
//dialogGenerate.set_progress(40);
|
|
|
//word.ScreenUpdating = false;
|
|
|
//if (bookmarks_docio == 1)
|
|
|
//{
|
|
|
// worddoc.Save();
|
|
|
// worddoc.Close();
|
|
|
// Fill_Bookmarks_from_Word(filename, docdata, "", "");
|
|
|
// worddoc = word.Documents.Open(filename);
|
|
|
//}
|
|
|
//else
|
|
|
//{
|
|
|
|
|
|
|
|
|
// //float progressstep = 1;
|
|
|
// //try
|
|
|
// //{
|
|
|
// // float b = 60;
|
|
|
// // progressstep = b / (float)docdata.DocValues.Count();
|
|
|
// //}
|
|
|
// //catch
|
|
|
// //{
|
|
|
|
|
|
// //}
|
|
|
// int usecount = 0;
|
|
|
// cursortm = "";
|
|
|
// Logging.Logging.Debug("Festlegung Used", "OnDoc", dokumentid);
|
|
|
// foreach (clsDocValue dv in docdata.DocValues)
|
|
|
// {
|
|
|
// //dv.used = 0;
|
|
|
// if (dv.TMBeginn.Contains("CompanyBBEB99")) { dv.used = 1; };
|
|
|
// if (dv.TMBeginn.Contains("EDKCursor"))
|
|
|
// {
|
|
|
// dv.used = 1;
|
|
|
// cursortm = dv.TMBeginn;
|
|
|
// }
|
|
|
// if (dv.FieldName.Contains("TGEDKCursor"))
|
|
|
// {
|
|
|
// dv.used = 1;
|
|
|
// cursorfeld = dv.FieldName;
|
|
|
// }
|
|
|
|
|
|
|
|
|
// if (dv.FieldName.ToString() != "") { dv.used = 1; };
|
|
|
// if (dv.used == 1) { usecount++; }
|
|
|
|
|
|
// }
|
|
|
// float progressstep = 1;
|
|
|
// try
|
|
|
// {
|
|
|
// float b = 40;
|
|
|
// progressstep = b / (float)usecount;
|
|
|
// }
|
|
|
// catch
|
|
|
// {
|
|
|
|
|
|
// }
|
|
|
// Logging.Logging.Debug("Used 1 Ende", "OnDoc", dokumentid);
|
|
|
|
|
|
// foreach (clsDocValue dv in docdata.DocValues)
|
|
|
// {
|
|
|
// dialogGenerate.add_progress((int)progressstep);
|
|
|
// if (dv.used == 0) { continue; }
|
|
|
// try
|
|
|
// {
|
|
|
// if (dv.TMBeginn.ToString().Contains("TGEDKCursor"))
|
|
|
// {
|
|
|
// cursorpositionieren = true;
|
|
|
// cursortm = dv.TMBeginn.ToString();
|
|
|
// }
|
|
|
// if (dv.FieldName.ToString().Contains("TGEDKCursor"))
|
|
|
// {
|
|
|
// cursorpositionieren = true;
|
|
|
// cursorfeld = dv.FieldName.ToString();
|
|
|
// }
|
|
|
// }
|
|
|
// catch { }
|
|
|
// // Logging.Logging.Debug(dv.TMBeginn.ToString() + " / " + dv.TMEnd.ToString(), dv.Value.ToString(), dokumentid);
|
|
|
// dialogGenerate.add_progress((int)progressstep);
|
|
|
|
|
|
// //20250119 - nur befüllte werte übermitteln'
|
|
|
|
|
|
// // if (dv.Value.ToString().Trim() != "")
|
|
|
// //{
|
|
|
// Logging.Logging.Debug(dv.TMBeginn.ToString() + " / " + dv.TMEnd.ToString() + " / " + dv.FieldName.ToString() + " => " + dv.Value.ToString(), "OnDoc", dokumentid);
|
|
|
// if (dv.TMBeginn.ToString() != "" && dv.TMEnd.ToString() == "" && !dv.TMBeginn.ToString().Contains("TGEDKCurosr"))
|
|
|
// {
|
|
|
|
|
|
// try
|
|
|
// {
|
|
|
// worddoc.Bookmarks[dv.TMBeginn.ToString()].Select();
|
|
|
// pos = worddoc.Bookmarks[dv.TMBeginn.ToString()].Start;
|
|
|
// word.Selection.Text = dv.Value.ToString();
|
|
|
// pos2 = word.Selection.End;
|
|
|
|
|
|
// if (dv.TMBeginn.Contains("TGEDKDirektTelefonB") || dv.TMBeginn.Contains("TGEDKVornameNameBetreue") || dv.TMBeginn.Contains("TGEDKDirektTelefonZ"))
|
|
|
// {
|
|
|
// Logging.Logging.Debug("1S - " + dv.TMBeginn.ToString(), "", dokumentid);
|
|
|
|
|
|
// word.Selection.MoveLeft(Unit: Microsoft.Office.Interop.Word.WdUnits.wdCharacter, Count: 1);
|
|
|
// if (editdoc) word.Selection.TypeText(Text: " ");
|
|
|
// word.Selection.SetRange(pos + 1, pos2 + 1);
|
|
|
// //var withBlock = worddoc.Bookmarks;
|
|
|
// //withBlock.Add(Range: word.Selection.Range, Name: dv.TMBeginn.ToString());
|
|
|
// //withBlock.DefaultSorting = Microsoft.Office.Interop.Word.WdBookmarkSortBy.wdSortByName;
|
|
|
// //withBlock.ShowHidden = false;
|
|
|
// worddoc.Bookmarks.Add(Range: word.Selection.Range, Name: dv.TMBeginn.ToString());
|
|
|
// Logging.Logging.Debug("1E - " + dv.TMBeginn.ToString(), "", dokumentid);
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// if (dv.TMBeginn.Contains("TGEDKDirektTelefonDokZ") || dv.TMBeginn.Contains("TGEDKVornameNameDokZ"))
|
|
|
// {
|
|
|
// Logging.Logging.Debug("2S - " + dv.TMBeginn.ToString(), "", dokumentid);
|
|
|
|
|
|
// word.Selection.Text = dv.Value.ToString();
|
|
|
// word.Selection.MoveLeft(Unit: Microsoft.Office.Interop.Word.WdUnits.wdCharacter, Count: 1);
|
|
|
// word.Selection.TypeText(Text: " ");
|
|
|
// word.Selection.SetRange(Start: pos + 1, End: pos2 + 1);
|
|
|
|
|
|
// //var withBlock = worddoc.Bookmarks;
|
|
|
// //withBlock.Add(Range: word.Selection.Range, Name: dv.TMBeginn.ToString());
|
|
|
// //withBlock.DefaultSorting = Microsoft.Office.Interop.Word.WdBookmarkSortBy.wdSortByName;
|
|
|
// //withBlock.ShowHidden = false;
|
|
|
// worddoc.Bookmarks.Add(Range: word.Selection.Range, Name: dv.TMBeginn.ToString());
|
|
|
// Logging.Logging.Debug("2E - " + dv.TMBeginn.ToString(), "", dokumentid);
|
|
|
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// Logging.Logging.Debug("3S - " + dv.TMBeginn.ToString(), "", dokumentid);
|
|
|
|
|
|
// word.Selection.SetRange(Start: pos, End: pos2);
|
|
|
// //var withBlock = worddoc.Bookmarks;
|
|
|
// //withBlock.Add(Range: word.Selection.Range, Name: dv.TMBeginn.ToString());
|
|
|
// //withBlock.DefaultSorting = Microsoft.Office.Interop.Word.WdBookmarkSortBy.wdSortByName;
|
|
|
// //withBlock.ShowHidden = false;
|
|
|
// worddoc.Bookmarks.Add(Range: word.Selection.Range, Name: dv.TMBeginn.ToString());
|
|
|
|
|
|
// Logging.Logging.Debug("3E - " + dv.TMBeginn.ToString(), "", dokumentid);
|
|
|
|
|
|
// }
|
|
|
// }
|
|
|
// Logging.Logging.Debug("4S - " + dv.TMBeginn.ToString(), "", dokumentid);
|
|
|
|
|
|
// word.Selection.MoveLeft(Unit: Microsoft.Office.Interop.Word.WdUnits.wdCharacter, Count: 1);
|
|
|
// word.Selection.MoveLeft(Unit: Microsoft.Office.Interop.Word.WdUnits.wdCharacter, Count: 2, Extend: Microsoft.Office.Interop.Word.WdMovementType.wdExtend);
|
|
|
// if (word.Selection.Text == " ")
|
|
|
// {
|
|
|
// word.Selection.MoveRight(Unit: Microsoft.Office.Interop.Word.WdUnits.wdCharacter, Count: 1);
|
|
|
// word.Selection.MoveLeft(Unit: Microsoft.Office.Interop.Word.WdUnits.wdCharacter, Count: 1, Extend: Microsoft.Office.Interop.Word.WdMovementType.wdExtend);
|
|
|
// word.Selection.Delete(Unit: Microsoft.Office.Interop.Word.WdUnits.wdCharacter, Count: 1);
|
|
|
// }
|
|
|
// Logging.Logging.Debug("4E - " + dv.TMBeginn.ToString(), "", dokumentid);
|
|
|
|
|
|
// }
|
|
|
// catch { }
|
|
|
// }
|
|
|
// if (dv.TMBeginn.ToString() != "" && dv.TMEnd.ToString() != "" && !dv.TMBeginn.ToString().Contains("TGEDKCursor"))
|
|
|
// {
|
|
|
// try
|
|
|
// {
|
|
|
// Logging.Logging.Debug("5S - " + dv.TMBeginn.ToString(), "", dokumentid);
|
|
|
|
|
|
// worddoc.Bookmarks[dv.TMBeginn.ToString()].Select();
|
|
|
// pos = worddoc.Bookmarks[dv.TMBeginn.ToString()].Start;
|
|
|
// worddoc.Bookmarks[dv.TMEnd.ToString()].Select();
|
|
|
// pos2 = worddoc.Bookmarks[dv.TMEnd.ToString()].Start;
|
|
|
// word.Selection.SetRange(pos, pos2);
|
|
|
// word.Selection.TypeText(Text: dv.Value.ToString());
|
|
|
// var withBlock = worddoc.Bookmarks;
|
|
|
// withBlock.Add(Range: word.Selection.Range, Name: dv.TMBeginn.ToString());
|
|
|
// withBlock.DefaultSorting = Microsoft.Office.Interop.Word.WdBookmarkSortBy.wdSortByName;
|
|
|
// withBlock.ShowHidden = false;
|
|
|
// Logging.Logging.Debug("5E - " + dv.TMBeginn.ToString(), "", dokumentid);
|
|
|
|
|
|
// }
|
|
|
// catch { }
|
|
|
// }
|
|
|
// if (dv.FieldName.ToString() != "" && !dv.FieldName.Contains("TGEDKCursor"))
|
|
|
// {
|
|
|
// try
|
|
|
// {
|
|
|
// Logging.Logging.Debug("6S - " + dv.TMBeginn.ToString(), "", dokumentid);
|
|
|
|
|
|
// if (dv.FieldName.Contains("cc_"))
|
|
|
// {
|
|
|
// word.ActiveDocument.SelectContentControlsByTag(dv.FieldName)[1].Range.Text = dv.Value;
|
|
|
// }
|
|
|
// if (worddoc.FormFields[dv.FieldName].TextInput.Width != 0)
|
|
|
// {
|
|
|
// int fieldlen = worddoc.FormFields[dv.FieldName].TextInput.Width;
|
|
|
// worddoc.FormFields[dv.FieldName].TextInput.Width = fieldlen + 5;
|
|
|
// }
|
|
|
// worddoc.FormFields[dv.FieldName.ToString()].Result = convert_wordfelder(dv.Value);
|
|
|
// Logging.Logging.Debug("6E - " + dv.TMBeginn.ToString(), "", dokumentid);
|
|
|
|
|
|
// }
|
|
|
// catch { }
|
|
|
// }
|
|
|
// //}
|
|
|
// }
|
|
|
//}
|
|
|
word.ScreenUpdating = true;
|
|
|
Logging.Logging.Debug("Word Befüllen Ende", "clsOffice", dokumentid);
|
|
|
|
|
|
if (docdata.Barcode == true) { Generate_Barcodes(ref docdata, tempdir); }
|
|
|
Logging.Logging.Debug("Barcodes", "clsOffice", dokumentid);
|
|
|
|
|
|
if (is_protected)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
worddoc.Protect(Type: Microsoft.Office.Interop.Word.WdProtectionType.wdAllowOnlyFormFields, NoReset: true, Password: "Australia");
|
|
|
}
|
|
|
catch { }
|
|
|
}
|
|
|
word.Visible = true;
|
|
|
worddoc.Activate();
|
|
|
word.Activate();
|
|
|
dialogGenerate.set_progress(90,"Macros ausführen");
|
|
|
Logging.Logging.Debug("Start Macros", "clsOffice", dokumentid);
|
|
|
|
|
|
if (!editdoc) run_macros(ref docdata, connectionstring);
|
|
|
|
|
|
if (cursorpositionieren)
|
|
|
{
|
|
|
try
|
|
|
|
|
|
{
|
|
|
if (cursortm != "") { worddoc.Bookmarks[cursortm].Select(); }
|
|
|
if (cursorfeld != "") { worddoc.FormFields[cursorfeld].Select(); }
|
|
|
}
|
|
|
catch { }
|
|
|
}
|
|
|
worddoc.Save();
|
|
|
Logging.Logging.Debug("Word Saved", "clsOffice", dokumentid);
|
|
|
|
|
|
worddoc.Close();
|
|
|
Logging.Logging.Debug("Word geschlossen", "clsOffice", dokumentid);
|
|
|
|
|
|
Thread.Sleep(OfficeSleep);
|
|
|
string b64 = fh.Base64FromFile(filename);
|
|
|
|
|
|
word.Documents.Open(filename);
|
|
|
word.Activate();
|
|
|
dialogGenerate.set_progress(100,"Generierung beendet");
|
|
|
Logging.Logging.Debug("Word geöffnet", "clsOffice", dokumentid);
|
|
|
|
|
|
word = null;
|
|
|
Logging.Logging.Debug("Generierung abgeschlossen", "clsOffice", dokumentid);
|
|
|
dialogGenerate.Close();
|
|
|
dialogGenerate.Dispose();
|
|
|
return b64;
|
|
|
|
|
|
//return fh.Base64FromFile(filename);
|
|
|
}
|
|
|
|
|
|
private void Kopfzeile_generieren()
|
|
|
{
|
|
|
Logging.Logging.Debug("Kopfzeile", "OnDoc", dokumentid);
|
|
|
word.Selection.HomeKey(Unit: Microsoft.Office.Interop.Word.WdUnits.wdStory);
|
|
|
if (word.ActiveWindow.View.SplitSpecial != Microsoft.Office.Interop.Word.WdSpecialPane.wdPaneNone)
|
|
|
{
|
|
|
word.ActiveWindow.Panes[2].Close();
|
|
|
}
|
|
|
if (word.ActiveWindow.ActivePane.View.Type == Microsoft.Office.Interop.Word.WdViewType.wdNormalView || word.ActiveWindow.ActivePane.View.Type == Microsoft.Office.Interop.Word.WdViewType.wdOutlineView)
|
|
|
{
|
|
|
word.ActiveWindow.ActivePane.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdPrintView;
|
|
|
}
|
|
|
word.ActiveWindow.ActivePane.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageHeader;
|
|
|
set_headerbookmark();
|
|
|
word.ActiveWindow.ActivePane.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument;
|
|
|
}
|
|
|
|
|
|
private void set_headerbookmark()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
worddoc.Bookmarks["TGEDKCompanyBBEB99"].Select();
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
word.Selection.MoveDown(Unit: Microsoft.Office.Interop.Word.WdUnits.wdLine, Count: 1);
|
|
|
{
|
|
|
var withBlock = word.ActiveDocument.Bookmarks;
|
|
|
withBlock.Add(Range: word.Selection.Range, Name: "TGEDKCompanyBBEB99");
|
|
|
withBlock.DefaultSorting = Microsoft.Office.Interop.Word.WdBookmarkSortBy.wdSortByName;
|
|
|
withBlock.ShowHidden = false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
private void HeaderFooterAnzeigen()
|
|
|
{
|
|
|
|
|
|
if (word.ActiveWindow.View.SplitSpecial != Microsoft.Office.Interop.Word.WdSpecialPane.wdPaneNone)
|
|
|
{
|
|
|
word.ActiveWindow.Panes[2].Close();
|
|
|
}
|
|
|
if (word.ActiveWindow.ActivePane.View.Type == Microsoft.Office.Interop.Word.WdViewType.wdNormalView || word.ActiveWindow.ActivePane.View.Type == Microsoft.Office.Interop.Word.WdViewType.wdOutlineView)
|
|
|
{
|
|
|
word.ActiveWindow.ActivePane.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdPrintView;
|
|
|
}
|
|
|
word.ActiveWindow.ActivePane.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageHeader;
|
|
|
if (word.Selection.HeaderFooter.IsHeader == true)
|
|
|
{
|
|
|
word.ActiveWindow.ActivePane.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageFooter;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
word.ActiveWindow.ActivePane.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageHeader;
|
|
|
}
|
|
|
}
|
|
|
public void Insert_Datamatrix(string filename)
|
|
|
{
|
|
|
object Form;
|
|
|
string strsel;
|
|
|
object strresult;
|
|
|
string s;
|
|
|
int dmposition;
|
|
|
// Selection.ShapeRange.Select
|
|
|
|
|
|
try
|
|
|
{
|
|
|
//object missing = System.Reflection.Missing.Value;
|
|
|
//object start1 = 0;
|
|
|
//object end1 = 0;
|
|
|
//Document adoc = word.Documents.Add(ref missing, ref missing, ref missing, ref missing);
|
|
|
//Microsoft.Office.Interop.Word.Range rng = adoc.Range(ref start1, ref missing);
|
|
|
|
|
|
|
|
|
string Zeichen;
|
|
|
Zeichen = " U";
|
|
|
int BarcodeFormatn = 0;
|
|
|
switch (BarcodeFormatn)
|
|
|
{
|
|
|
case 0:
|
|
|
{
|
|
|
word.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
|
|
|
word.Selection.HomeKey(Unit: Microsoft.Office.Interop.Word.WdUnits.wdLine, Extend: Microsoft.Office.Interop.Word.WdMovementType.wdExtend);
|
|
|
word.Selection.Delete(Unit: Microsoft.Office.Interop.Word.WdUnits.wdCharacter, Count: 1);
|
|
|
word.Selection.InlineShapes.AddPicture(filename, LinkToFile: false, SaveWithDocument: true);
|
|
|
break;
|
|
|
}
|
|
|
case 1:
|
|
|
{
|
|
|
word.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
|
|
|
word.Selection.HomeKey(Unit: Microsoft.Office.Interop.Word.WdUnits.wdLine, Extend: Microsoft.Office.Interop.Word.WdMovementType.wdExtend);
|
|
|
word.Selection.Delete(Unit: Microsoft.Office.Interop.Word.WdUnits.wdCharacter, Count: 1);
|
|
|
word.Selection.InlineShapes.AddPicture(filename, LinkToFile: false, SaveWithDocument: true);
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
case 2:
|
|
|
{
|
|
|
word.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
|
|
|
word.Selection.HomeKey(Unit: Microsoft.Office.Interop.Word.WdUnits.wdLine, Extend: Microsoft.Office.Interop.Word.WdMovementType.wdExtend);
|
|
|
word.Selection.Delete(Unit: Microsoft.Office.Interop.Word.WdUnits.wdCharacter, Count: 1);
|
|
|
word.Selection.InlineShapes.AddPicture(filename, LinkToFile: false, SaveWithDocument: true);
|
|
|
break;
|
|
|
}
|
|
|
case 3:
|
|
|
{
|
|
|
word.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
|
|
|
word.Selection.HomeKey(Unit: Microsoft.Office.Interop.Word.WdUnits.wdLine, Extend: Microsoft.Office.Interop.Word.WdMovementType.wdExtend);
|
|
|
word.Selection.Delete(Unit: Microsoft.Office.Interop.Word.WdUnits.wdCharacter, Count: 1);
|
|
|
word.Selection.InlineShapes.AddPicture(filename, LinkToFile: false, SaveWithDocument: true);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
Form = null;
|
|
|
return;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
}
|
|
|
}
|
|
|
private System.Drawing.Image ResizeImage(System.Drawing.Image imgToResize, Size size)
|
|
|
{
|
|
|
// Get the image current width
|
|
|
int sourceWidth = imgToResize.Width;
|
|
|
// Get the image current height
|
|
|
int sourceHeight = imgToResize.Height;
|
|
|
float nPercent = 0;
|
|
|
float nPercentW = 0;
|
|
|
float nPercentH = 0;
|
|
|
// Calculate width and height with new desired size
|
|
|
nPercentW = ((float)size.Width / (float)sourceWidth);
|
|
|
nPercentH = ((float)size.Height / (float)sourceHeight);
|
|
|
nPercent = Math.Min(nPercentW, nPercentH);
|
|
|
// New Width and Height
|
|
|
int destWidth = (int)(sourceWidth * nPercent);
|
|
|
int destHeight = (int)(sourceHeight * nPercent);
|
|
|
Bitmap b = new Bitmap(destWidth, destHeight);
|
|
|
Graphics g = Graphics.FromImage((System.Drawing.Image)b);
|
|
|
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
|
|
// Draw image with new width and height
|
|
|
g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
|
|
|
g.Dispose();
|
|
|
return (System.Drawing.Image)b;
|
|
|
}
|
|
|
private void Generate_Barcodes(ref clsDocData docdata, string tempdir)
|
|
|
{
|
|
|
Logging.Logging.Debug("Barcode genererien start", "OnDoc clsOffice", dokumentid);
|
|
|
vbBarcodes.vbarcodes vbcode = new vbBarcodes.vbarcodes();
|
|
|
vbcode.GenerateBarcodes(ref word, ref docdata, connectstring, tempdir);
|
|
|
vbcode = null;
|
|
|
Logging.Logging.Debug("Barcode genererien Ende", "OnDoc clsOffice", dokumentid);
|
|
|
return;
|
|
|
|
|
|
float left = 360;
|
|
|
float top = 793;
|
|
|
float width = 200;
|
|
|
float height = 33;
|
|
|
word.Selection.HomeKey(Unit: Microsoft.Office.Interop.Word.WdUnits.wdStory);
|
|
|
Microsoft.Office.Interop.Word.WdStatistic stat = Microsoft.Office.Interop.Word.WdStatistic.wdStatisticPages;
|
|
|
int pages = worddoc.ComputeStatistics(stat, null);
|
|
|
for (int i = 1; i <= pages; i++)
|
|
|
{
|
|
|
|
|
|
string xname = i.ToString().Trim();
|
|
|
try
|
|
|
{
|
|
|
word.Selection.GoTo(What: Microsoft.Office.Interop.Word.WdGoToItem.wdGoToPage, xname);
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
Logging.Logging.Debug("Word GotoPage " + xname + " " + e.Message, "OnDoc clsOffice", dokumentid);
|
|
|
}
|
|
|
HeaderFooterAnzeigen();
|
|
|
if (docdata.barcode_type == "1")
|
|
|
{
|
|
|
System.Drawing.Image barcodeimage;
|
|
|
BarcodeLib.Barcode Barcode = new BarcodeLib.Barcode();
|
|
|
barcodeimage = Barcode.Get_Datamatrix(DataMatrix.net.DmtxScheme.DmtxSchemeAscii, docdata.barcode_content, 6, 6, 0, "Right", docdata.barcode_text, docdata.Zusatz_Font, docdata.Zusatz_FontSize);
|
|
|
barcodeimage = ResizeImage(barcodeimage, new Size(200, 80));
|
|
|
barcodeimage.Save(word.ActiveDocument.FullName + ".png");
|
|
|
Insert_Datamatrix(word.ActiveDocument.FullName + ".png");
|
|
|
System.IO.File.Delete(word.ActiveDocument.FullName + ".png");
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//System.Drawing.Image barcodeimage;
|
|
|
//BarcodeLib.Barcode Barcode = new BarcodeLib.Barcode();
|
|
|
//barcodeimage = Barcode.Get_LinerBarcode(Barcoded.Symbology.I2of5, dokumentid.Substring(6, 16), dokumentid.Substring(6, 16) + docdata.barcode_zusatz, docdata.barcode_textposition, docdata.Zusatz_Font, Convert.ToInt32(docdata.Zusatz_FontSize), 0);
|
|
|
//barcodeimage.Save(word.ActiveDocument.FullName + ".png");
|
|
|
//Insert_Datamatrix(word.ActiveDocument.FullName + ".png");
|
|
|
//System.IO.File.Delete(word.ActiveDocument.FullName + ".png");
|
|
|
//return;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
word.Selection.HeaderFooter.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, docdata.barcode_left, docdata.barcode_top, docdata.barcode_width, docdata.barcode_height).Select();
|
|
|
|
|
|
word.Selection.ShapeRange.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
|
|
|
word.Selection.ShapeRange.TextFrame.MarginLeft = 0;
|
|
|
word.Selection.ShapeRange.TextFrame.MarginTop = 0;
|
|
|
word.Selection.ShapeRange.TextFrame.MarginRight = 0;
|
|
|
word.Selection.ShapeRange.TextFrame.MarginBottom = 0;
|
|
|
|
|
|
word.ActiveDocument.Tables.Add(Range: word.Selection.Range, NumRows: 1, NumColumns: 1);
|
|
|
|
|
|
if (docdata.barcode_horizontal == 0)
|
|
|
{
|
|
|
word.Selection.Tables[1].Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft].LineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone;
|
|
|
word.Selection.Tables[1].Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderRight].LineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone;
|
|
|
word.Selection.Tables[1].Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop].LineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone;
|
|
|
word.Selection.Tables[1].Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom].LineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone;
|
|
|
word.Selection.Tables[1].Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].LineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone;
|
|
|
word.Selection.Tables[1].Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalUp].LineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone;
|
|
|
word.Selection.Orientation = Microsoft.Office.Interop.Word.WdTextOrientation.wdTextOrientationUpward;
|
|
|
word.Selection.Tables[1].Rows.HeightRule = Microsoft.Office.Interop.Word.WdRowHeightRule.wdRowHeightAtLeast;
|
|
|
word.Selection.Tables[1].Rows.Height = 150;
|
|
|
}
|
|
|
|
|
|
word.Selection.TypeText(Bar25I(dokumentid.Substring(6, 16)));
|
|
|
word.Selection.HomeKey(Unit: Microsoft.Office.Interop.Word.WdUnits.wdLine, Extend: Microsoft.Office.Interop.Word.WdMovementType.wdExtend);
|
|
|
word.Selection.Font.Name = docdata.barcode_font;
|
|
|
word.Selection.Font.Size = docdata.barcode_fontsize;
|
|
|
|
|
|
word.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
|
|
|
word.Selection.EndKey(Unit: Microsoft.Office.Interop.Word.WdUnits.wdLine);
|
|
|
word.Selection.Font.Name = docdata.Zusatz_Font;
|
|
|
word.Selection.Font.Size = docdata.Zusatz_FontSize;
|
|
|
word.Selection.TypeText(docdata.barcode_zusatz);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
public string get_unterschrift(string input)
|
|
|
{
|
|
|
|
|
|
string URL = resturi + "API/GetUnterschriftAsBase64ByMitarbeiternr?MaNr=" + input;
|
|
|
|
|
|
HttpWebRequest webRequest = HttpWebRequest.Create(URL) as HttpWebRequest;
|
|
|
webRequest.Method = WebRequestMethods.Http.Get;
|
|
|
webRequest.Headers["Authorization"] = "Bearer " + apikey;
|
|
|
try
|
|
|
{
|
|
|
using (HttpWebResponse response = webRequest.GetResponse() as HttpWebResponse)
|
|
|
{
|
|
|
if (response.StatusCode == HttpStatusCode.OK)
|
|
|
{
|
|
|
StreamReader reader = new StreamReader(response.GetResponseStream());
|
|
|
string responseContent = reader.ReadToEnd();
|
|
|
|
|
|
return responseContent;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Logging.Logging.Error(URL + ": " + response.StatusCode.ToString() + " / " + response.StatusDescription, "Clinet - DokList GetDocument", "");
|
|
|
return "";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
return "";
|
|
|
}
|
|
|
}
|
|
|
public void Replace_Text(ref WordDocument wordDocument, string TextToReplace, string NewText)
|
|
|
{
|
|
|
wordDocument.Replace(TextToReplace, NewText, true, true);
|
|
|
}
|
|
|
|
|
|
public void ReplaceBookmarkContent(ref WordDocument document, String bookmark1, String bookmark2, String replacementContent)
|
|
|
{
|
|
|
//Temp Bookmark.
|
|
|
String tempBookmarkName = "tempBookmark";
|
|
|
|
|
|
#region Insert bookmark start after bookmark1.
|
|
|
//Get the bookmark instance by using FindByName method of BookmarkCollection with bookmark name.
|
|
|
Syncfusion.DocIO.DLS.Bookmark firstBookmark = document.Bookmarks.FindByName(bookmark1);
|
|
|
//Access the bookmark end’s owner paragraph by using bookmark.
|
|
|
WParagraph firstBookmarkOwnerPara = firstBookmark.BookmarkEnd.OwnerParagraph;
|
|
|
//Get the index of bookmark end of bookmark1.
|
|
|
int index = firstBookmarkOwnerPara.Items.IndexOf(firstBookmark.BookmarkEnd);
|
|
|
//Create and add new bookmark start after bookmark1.
|
|
|
BookmarkStart newBookmarkStart = new BookmarkStart(document, tempBookmarkName);
|
|
|
firstBookmarkOwnerPara.ChildEntities.Insert(index + 1, newBookmarkStart);
|
|
|
#endregion
|
|
|
|
|
|
#region Insert bookmark end before bookmark2.
|
|
|
//Get the bookmark instance by using FindByName method of BookmarkCollection with bookmark name.
|
|
|
Syncfusion.DocIO.DLS.Bookmark secondBookmark = document.Bookmarks.FindByName(bookmark2);
|
|
|
//Access the bookmark start’s owner paragraph by using bookmark.
|
|
|
WParagraph secondBookmarkOwnerPara = secondBookmark.BookmarkStart.OwnerParagraph;
|
|
|
//Get the index of bookmark start of bookmark2.
|
|
|
index = secondBookmarkOwnerPara.Items.IndexOf(secondBookmark.BookmarkStart);
|
|
|
//Create and add new bookmark end before bookmark2.
|
|
|
BookmarkEnd newBookmarkEnd = new BookmarkEnd(document, tempBookmarkName);
|
|
|
secondBookmarkOwnerPara.ChildEntities.Insert(index, newBookmarkEnd);
|
|
|
#endregion
|
|
|
|
|
|
#region Select bookmark content and replace.
|
|
|
//Create the bookmark navigator instance to access the newly created bookmark.
|
|
|
BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
|
|
|
//Move the virtual cursor to the location of the temp bookmark.
|
|
|
bookmarkNavigator.MoveToBookmark(tempBookmarkName);
|
|
|
//Replace the bookmark content.
|
|
|
bookmarkNavigator.ReplaceBookmarkContent(replacementContent, true);
|
|
|
#endregion
|
|
|
|
|
|
#region Remove that temporary bookmark.
|
|
|
//Get the bookmark instance by using FindByName method of BookmarkCollection with bookmark name.
|
|
|
Syncfusion.DocIO.DLS.Bookmark bookmark = document.Bookmarks.FindByName(tempBookmarkName);
|
|
|
//Remove the temp bookmark named from Word document.
|
|
|
document.Bookmarks.Remove(bookmark);
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
public void Fill_Bookmarks_from_Word(string filename, clsDocData docdata, string img_UL = "", string img_UR = "")
|
|
|
{
|
|
|
using (FileStream inputFileStream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) ;
|
|
|
WordDocument document = new WordDocument();
|
|
|
document.Open(filename, FormatType.Automatic);
|
|
|
Word_Compatibility_Mode(ref document);
|
|
|
//CompatibilityMode compatibilityMode = document.Settings.CompatibilityMode;
|
|
|
|
|
|
//var formattype_original = document.ActualFormatType;
|
|
|
//switch (compatibilityMode)
|
|
|
//{
|
|
|
// case CompatibilityMode.Word2010:
|
|
|
// document.Settings.CompatibilityMode = CompatibilityMode.Word2010;
|
|
|
// break;
|
|
|
// case CompatibilityMode.Word2013:
|
|
|
// document.Settings.CompatibilityMode = CompatibilityMode.Word2010;
|
|
|
// break;
|
|
|
// default:
|
|
|
// document.Settings.CompatibilityMode = CompatibilityMode.Word2003;
|
|
|
// break;
|
|
|
//}
|
|
|
foreach (clsDocValue dv in docdata.DocValues)
|
|
|
{
|
|
|
Logging.Logging.Debug("Fill_Bookmarks_from_Word " + dv.TMBeginn.ToString(), "OfficeLib", "");
|
|
|
if (docdata.Form_ohne_Unterschrift == "True")
|
|
|
{
|
|
|
|
|
|
foreach (clsDocValue dv2 in docdata.DocValues)
|
|
|
{
|
|
|
if (dv2.TMBeginn.ToString().Contains("VornameNameLinks")) { dv2.Value = ""; }
|
|
|
if (dv2.TMBeginn.ToString().Contains("VornameNameRechts")) { dv2.Value = ""; }
|
|
|
if (dv2.TMBeginn.ToString().Contains("TGEDKFunktionLinks")) { dv2.Value = ""; }
|
|
|
if (dv2.TMBeginn.ToString().Contains("FunktionRechts")) { dv2.Value = ""; }
|
|
|
//clsNameVOrnameTM tm = docdata.VornameNameTextmarken.Find(x => x.TM == dv2.TMBeginn.ToString());
|
|
|
//if (tm != null) {
|
|
|
// dv2.Value = "";
|
|
|
// }
|
|
|
//if (dv2.TMBeginn.ToString() == "TGEDKVornameNameLinksB99") { dv2.Value = ""; }
|
|
|
//if (dv2.TMBeginn.ToString() == "TGEDKVornameNameRechtsB99") { dv2.Value = ""; }
|
|
|
//if (dv2.TMBeginn.ToString() == "TGEDKFunktionLinksB99") { dv2.Value = ""; }
|
|
|
//if (dv2.TMBeginn.ToString() == "TGEDKFunktionRechtsB99") { dv2.Value = ""; }
|
|
|
}
|
|
|
}
|
|
|
if (dv.TMBeginn.ToString() != "" && dv.TMEnd.ToString() == "")
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
|
|
|
|
|
|
|
|
|
// if ((dv.TMBeginn.ToString() == "TGEDKVornameNameLinksB99" || dv.TMBeginn.ToString() == "TGEDKVornameNameRechtsB99") && docdata.As_Faksimile == "True")
|
|
|
if ((dv.TMBeginn.ToString().Contains("VornameNameLinks") || dv.TMBeginn.ToString().Contains("VornameNameRechts")) && docdata.As_Faksimile == "True")
|
|
|
{
|
|
|
Logging.Logging.Debug(dv.TMBeginn.ToString() + " / " + dv.Value.ToString(), "clsOffice", "");
|
|
|
string funktionlinks = "";
|
|
|
string funktionrechts = "";
|
|
|
foreach (clsDocValue dv2 in docdata.DocValues)
|
|
|
{
|
|
|
//if (dv2.TMBeginn.ToString() == "TGEDKFunktionLinksB99") { funktionlinks = dv2.Value.ToString(); }
|
|
|
//if (dv2.TMBeginn.ToString() == "TGEDKFunktionRechtsB99") { funktionrechts = dv2.Value.ToString(); }
|
|
|
if (dv2.TMBeginn.ToString().Contains("FunktionLinks")) { funktionlinks = dv2.Value.ToString(); }
|
|
|
if (dv2.TMBeginn.ToString().Contains("FunktionRecht")) { funktionrechts = dv2.Value.ToString(); }
|
|
|
}
|
|
|
bookmarkNavigator.MoveToBookmark(dv.TMBeginn.ToString());
|
|
|
IWParagraph paragraph = new WParagraph(document);
|
|
|
paragraph.AppendBreak(BreakType.LineBreak);
|
|
|
|
|
|
// if (dv.TMBeginn.ToString() == "TGEDKVornameNameLinksB99")
|
|
|
if (dv.TMBeginn.ToString().Contains("VornameNameLinks"))
|
|
|
{
|
|
|
string unterschrift = "";
|
|
|
if (img_UL != "") { unterschrift = img_UL.ToString(); }
|
|
|
else
|
|
|
{
|
|
|
unterschrift = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(get_unterschrift(docdata.Unterschrift_Links));
|
|
|
}
|
|
|
if (unterschrift != "")
|
|
|
{
|
|
|
MemoryStream mssign = new MemoryStream(Convert.FromBase64String(unterschrift));
|
|
|
System.Drawing.Image img = System.Drawing.Image.FromStream(mssign);
|
|
|
paragraph.AppendPicture(img);
|
|
|
mssign.Dispose();
|
|
|
img.Dispose();
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string unterschrift = "";
|
|
|
|
|
|
if (img_UR != "") { unterschrift = img_UR; }
|
|
|
else
|
|
|
{
|
|
|
unterschrift = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(get_unterschrift(docdata.Unterschrift_Rechts));
|
|
|
}
|
|
|
if (unterschrift != "")
|
|
|
{
|
|
|
MemoryStream mssign = new MemoryStream(Helper.EncodeExtensions.DecodeBase642ByteArray(unterschrift));
|
|
|
System.Drawing.Image img = System.Drawing.Image.FromStream(mssign);
|
|
|
mssign.Dispose();
|
|
|
paragraph.AppendPicture(img);
|
|
|
img.Dispose();
|
|
|
}
|
|
|
}
|
|
|
// System.Drawing.Image image = System.Drawing.Image.FromFile(@"x:\docdemo\unterschriften\kube1.png");
|
|
|
//paragraph.AppendPicture(image);
|
|
|
paragraph.AppendBreak(BreakType.LineBreak);
|
|
|
paragraph.AppendText(dv.Value.ToString());
|
|
|
//if (dv.TMBeginn.ToString() == "TGEDKVornameNameLinksB99")
|
|
|
if (dv.TMBeginn.ToString().Contains("VornameNameLinks"))
|
|
|
{
|
|
|
paragraph.AppendBreak(BreakType.LineBreak);
|
|
|
paragraph.AppendText(funktionlinks);
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
paragraph.AppendBreak(BreakType.LineBreak);
|
|
|
paragraph.AppendText(funktionrechts);
|
|
|
|
|
|
}
|
|
|
//paragraph.rep
|
|
|
bookmarkNavigator.InsertParagraph(paragraph);
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
// if (docdata.As_Faksimile == "True" && (dv.TMBeginn.ToString() == "TGEDKFunktionLinksB99" || dv.TMBeginn.ToString() == "TGEDKFunktionRechtsB99"))
|
|
|
if (docdata.As_Faksimile == "True" && (dv.TMBeginn.ToString().Contains("FunktionLinks") || dv.TMBeginn.ToString().Contains("FunktionRechts")))
|
|
|
{
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Syncfusion.DocIO.DLS.Bookmark bookmark;
|
|
|
bookmark = document.Bookmarks.FindByName(dv.TMBeginn.ToString());
|
|
|
if (bookmark != null)
|
|
|
{
|
|
|
bookmarkNavigator.MoveToBookmark(dv.TMBeginn.ToString(), true, false);
|
|
|
//bookmarkNavigator.MoveToBookmark(dv.TMBeginn.ToString());
|
|
|
//bookmarkNavigator.InsertText(dv.Value.ToString());
|
|
|
bookmarkNavigator.ReplaceBookmarkContent(dv.Value.ToString(), true);
|
|
|
//TextBodyPart bookmarkContent = bookmarkNavigator.GetBookmarkContent();
|
|
|
//string bookmarkText = ((Syncfusion.DocIO.DLS.WParagraph)bookmarkContent.BodyItems.FirstItem).Text;
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
catch { }
|
|
|
}
|
|
|
if (dv.TMBeginn.ToString() != "" && dv.TMEnd.ToString() != "")
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
ReplaceBookmarkContent(ref document, dv.TMBeginn.ToString(), dv.TMEnd.ToString(), dv.Value.ToString());
|
|
|
}
|
|
|
catch { }
|
|
|
}
|
|
|
|
|
|
if (dv.FieldName.ToString() != "")
|
|
|
{
|
|
|
if (dv.FieldName.ToString().Substring(0, 2) == "$$")
|
|
|
{
|
|
|
Replace_Text(ref document, dv.FieldName.ToString(), dv.Value.ToString());
|
|
|
}
|
|
|
try
|
|
|
{
|
|
|
foreach (WSection section in document.Sections)
|
|
|
//Iterates through section child elements
|
|
|
foreach (WTextBody textBody in section.ChildEntities)
|
|
|
{
|
|
|
//Iterates through form fields
|
|
|
foreach (WFormField formField in textBody.FormFields)
|
|
|
{
|
|
|
if (formField.Name == dv.FieldName.ToString())
|
|
|
{
|
|
|
formField.Text = dv.Value.ToString();
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch { }
|
|
|
}
|
|
|
|
|
|
}
|
|
|
document.Save(filename);
|
|
|
document.Dispose();
|
|
|
document = null;
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
public bool insert_signature(string dokumentid, string unterschriftlinks, string unterschriftrechts, string tempdir, string dokumenttypnr )
|
|
|
{
|
|
|
DB db = new DB(this.connectstring);
|
|
|
System.Data.DataTable dt = new System.Data.DataTable();
|
|
|
System.Data.DataTable dt2 = new System.Data.DataTable();
|
|
|
string Apptype = "";
|
|
|
string Extension = "";
|
|
|
dt = db.Get_Vorlage_By_DokumentID(dokumentid, true, tempdir, true);
|
|
|
db.dsdaten.Tables.Clear();
|
|
|
dt2 = db.Get_ApplicationType_from_Vorlage(Convert.ToInt32(dt.Rows[0]["nr"].ToString()));
|
|
|
Apptype = dt2.Rows[0][0].ToString();
|
|
|
Extension = dt2.Rows[0][1].ToString();
|
|
|
switch (Apptype.ToUpper())
|
|
|
{
|
|
|
case "DOCX":
|
|
|
case "DOCM":
|
|
|
case "DOC":
|
|
|
case "DOT":
|
|
|
case "WORD":
|
|
|
case "DOTM":
|
|
|
string filename = tempdir + dokumentid + ".sig";
|
|
|
Helper.clsFileHelper fh = new Helper.clsFileHelper();
|
|
|
fh.SaveBase64ToFile(dt.Rows[0][0].ToString(), filename);
|
|
|
Start_Application();
|
|
|
//word.Visible = true;
|
|
|
word.Documents.Open(filename);
|
|
|
//word.Visible = true;
|
|
|
|
|
|
|
|
|
string path_unterschriftlinks = "";
|
|
|
string path_unterschriftrechts = "";
|
|
|
if ( unterschriftlinks != "-1")
|
|
|
{
|
|
|
unterschriftlinks = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(get_unterschrift(unterschriftlinks));
|
|
|
Helper.clsFileHelper clsFileHelper = new Helper.clsFileHelper();
|
|
|
path_unterschriftlinks = tempdir + dokumentid + "UL.png";
|
|
|
clsFileHelper.SaveBase64ToFile(unterschriftlinks, path_unterschriftlinks);
|
|
|
}
|
|
|
if (unterschriftrechts != "-1")
|
|
|
{
|
|
|
unterschriftrechts = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(get_unterschrift(unterschriftrechts));
|
|
|
Helper.clsFileHelper clsFileHelper = new Helper.clsFileHelper();
|
|
|
path_unterschriftrechts = tempdir + dokumentid + "UR.png";
|
|
|
clsFileHelper.SaveBase64ToFile(unterschriftrechts, path_unterschriftrechts);
|
|
|
}
|
|
|
word_signature word_Signature = new word_signature(this.connectstring);
|
|
|
word_Signature.sign_doc(ref word, path_unterschriftlinks, path_unterschriftrechts, dokumentid,dokumenttypnr);
|
|
|
if (System.IO.File.Exists(path_unterschriftlinks)) { System.IO.File.Delete(tempdir + dokumentid + "UL.png"); };
|
|
|
if (System.IO.File.Exists(path_unterschriftrechts)) { System.IO.File.Delete(tempdir + dokumentid + "UR.png"); }
|
|
|
|
|
|
word.ActiveDocument.Save();
|
|
|
word.ActiveDocument.Close();
|
|
|
word.Quit(false);
|
|
|
|
|
|
db.Save_To_DB(dokumentid, filename, "", 0);
|
|
|
System.IO.File.Delete(filename);
|
|
|
return true;
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public class word_signature
|
|
|
{
|
|
|
|
|
|
private string ConnectionString = "";
|
|
|
|
|
|
public word_signature(string connectionstring)
|
|
|
{
|
|
|
ConnectionString = connectionstring.Trim();
|
|
|
}
|
|
|
bool is_protected = false;
|
|
|
Microsoft.Office.Interop.Word.Document docWord;
|
|
|
Microsoft.Office.Interop.Word.Application word;
|
|
|
public bool sign_doc(ref Microsoft.Office.Interop.Word.Application word, string imagepath_ul, string imagepath_ur, string dokumentid, string dokumenttypnr)
|
|
|
{
|
|
|
Logging.Logging.Debug("Sign_Doc", "OnDoc", dokumentid);
|
|
|
docWord = word.ActiveDocument;
|
|
|
this.word = word;
|
|
|
|
|
|
DB db = new DB(this.ConnectionString);
|
|
|
db.clear_parameter();
|
|
|
db.add_parameter("@dokumenttypnr",dokumenttypnr.ToString());
|
|
|
db.add_parameter("@officeversion", "2016");
|
|
|
db.Get_Tabledata("sp_signatureposition", true,false);
|
|
|
System.Data.DataTable position = db.dsdaten.Tables[0];
|
|
|
db = null;
|
|
|
Thread.Sleep(1000);
|
|
|
if (word.ActiveDocument.ProtectionType != Microsoft.Office.Interop.Word.WdProtectionType.wdNoProtection)
|
|
|
{
|
|
|
word.ActiveDocument.Unprotect(Password: "Australia");
|
|
|
is_protected = true;
|
|
|
}
|
|
|
|
|
|
int w = 0;
|
|
|
int h = 0;
|
|
|
int l = 0;
|
|
|
int t = 0;
|
|
|
int type = 1;
|
|
|
try
|
|
|
{
|
|
|
List<string> list = new List<string>();
|
|
|
foreach (Microsoft.Office.Interop.Word.Bookmark bm in docWord.Bookmarks)
|
|
|
{
|
|
|
if (bm.Name.Contains("VornameNameLinks") || bm.Name.Contains("UnterschriftLinks") || bm.Name == "TGEDKVornameNameL") { list.Add(bm.Name); }
|
|
|
if (bm.Name.Contains("VornameNameRechts") || bm.Name.Contains("UnterschriftRechts") || bm.Name == "TGEDKVornameNameR") { list.Add(bm.Name); }
|
|
|
|
|
|
}
|
|
|
list.Sort();
|
|
|
foreach (string bm in list)
|
|
|
{
|
|
|
if (bm.Contains("VornameNameLinks") || bm.Contains("UnterschriftLinks") || bm=="TGEDKVornameNameL")
|
|
|
{
|
|
|
foreach (System.Data.DataRow dr in position.Rows)
|
|
|
{
|
|
|
if (bm.ToUpper() == dr["bookmark"].ToString().ToUpper())
|
|
|
{
|
|
|
l = Convert.ToInt32(dr["posleft"]);
|
|
|
t = Convert.ToInt32(dr["postop"]);
|
|
|
w = Convert.ToInt32(dr["width"]);
|
|
|
h = Convert.ToInt32(dr["height"]);
|
|
|
type = Convert.ToInt32(dr["type"]);
|
|
|
}
|
|
|
}
|
|
|
insert_unterschrift(bm, imagepath_ul,l,t,w,h,type);
|
|
|
}
|
|
|
if (bm.Contains("VornameNameRechts") || bm.Contains("UnterschriftRechts") || bm == "TGEDKVornameNameR")
|
|
|
{
|
|
|
foreach (System.Data.DataRow dr in position.Rows)
|
|
|
{
|
|
|
if (bm.ToUpper() == dr["bookmark"].ToString().ToUpper())
|
|
|
{
|
|
|
l = Convert.ToInt32(dr["posleft"]);
|
|
|
t = Convert.ToInt32(dr["postop"]);
|
|
|
w = Convert.ToInt32(dr["width"]);
|
|
|
h = Convert.ToInt32(dr["height"]);
|
|
|
type = Convert.ToInt32(dr["type"]);
|
|
|
}
|
|
|
}
|
|
|
insert_unterschrift(bm, imagepath_ur,l,t,w,h,type);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
//docword = docWord; ;
|
|
|
if (is_protected)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
word.ActiveDocument.Protect(Type: Microsoft.Office.Interop.Word.WdProtectionType.wdAllowOnlyFormFields, NoReset: true, Password: "Australia");
|
|
|
}
|
|
|
catch { }
|
|
|
}
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
Logging.Logging.Debug("Ende Sign_Doc", "OnDoc", dokumentid);
|
|
|
return true;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Logging.DocLog.Error("Signaturen konnten nicht eingefügt werden", "OnDocOffe", dokumentid,"",ex.Message);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void insert_unterschrift(string bookmark, string imagepath, int l, int t, int w, int h, int type)
|
|
|
{
|
|
|
if (imagepath == "") return;
|
|
|
|
|
|
object missing = Type.Missing;
|
|
|
if (type == 1)
|
|
|
{
|
|
|
Microsoft.Office.Interop.Word.Range myRange = docWord.Bookmarks[bookmark].Range;
|
|
|
Microsoft.Office.Interop.Word.Bookmark bm = docWord.Bookmarks[bookmark];
|
|
|
bm.Range.GoTo();
|
|
|
bm.Select();
|
|
|
Thread.Sleep(500);
|
|
|
System.Windows.Forms.Application.DoEvents();
|
|
|
Microsoft.Office.Interop.Word.Shape myShape1 = docWord.Shapes.AddPicture(imagepath, false, true, 0, 0, 120, 50, missing);
|
|
|
//myShape1.Top = myShape1.Top - myShape1.Height;
|
|
|
myShape1.Top = myShape1.Top + t;
|
|
|
myShape1.Left = myShape1.Left + l;
|
|
|
myShape1.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapBehind;
|
|
|
}
|
|
|
if (type == 2)
|
|
|
{
|
|
|
Microsoft.Office.Interop.Word.Bookmark bm = docWord.Bookmarks[bookmark];
|
|
|
float vertical = bm.Range.Information[Microsoft.Office.Interop.Word.WdInformation.wdVerticalPositionRelativeToPage];
|
|
|
float horizontal = bm.Range.Information[Microsoft.Office.Interop.Word.WdInformation.wdHorizontalPositionRelativeToPage];
|
|
|
float marigntop = docWord.PageSetup.TopMargin;
|
|
|
float marginleft = docWord.PageSetup.LeftMargin;
|
|
|
|
|
|
docWord.Activate();
|
|
|
bm.Range.GoTo();
|
|
|
bm.Select();
|
|
|
|
|
|
Microsoft.Office.Interop.Word.Shape myShape = docWord.Shapes.AddPicture(imagepath, false, true, 0, 0, 120, 50, missing);
|
|
|
myShape.RelativeHorizontalPosition = Microsoft.Office.Interop.Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;
|
|
|
myShape.RelativeVerticalPosition = Microsoft.Office.Interop.Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionPage;
|
|
|
myShape.Left = horizontal + l;
|
|
|
myShape.Top = vertical + t;
|
|
|
myShape.Name = "Unterschrift_" + bookmark;
|
|
|
|
|
|
Logging.Logging.Debug(horizontal.ToString() + "/" + vertical.ToString() + "/" + marginleft.ToString() + "/" + marigntop.ToString() + "/" + myShape.Top.ToString() + "/" + myShape.Left.ToString(), "OnDoc", "");
|
|
|
|
|
|
myShape.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoTrue;
|
|
|
myShape.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapBehind;
|
|
|
}
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//docWord.Activate();
|
|
|
//object missing = Type.Missing;
|
|
|
//Microsoft.Office.Interop.Word.Range myRange = docWord.Bookmarks[bookmark].Range;
|
|
|
|
|
|
//Microsoft.Office.Interop.Word.Bookmark bm = docWord.Bookmarks[bookmark];
|
|
|
|
|
|
//float vertical = bm.Range.Information[Microsoft.Office.Interop.Word.WdInformation.wdVerticalPositionRelativeToPage];
|
|
|
//float horizontal = bm.Range.Information[Microsoft.Office.Interop.Word.WdInformation.wdHorizontalPositionRelativeToPage];
|
|
|
//bm.Select();
|
|
|
|
|
|
//docWord.Activate();
|
|
|
//Microsoft.Office.Interop.Word.Range myRange3 = bm.Range;
|
|
|
//Microsoft.Office.Interop.Word.Range myRange4 = bm.Range.GoTo();
|
|
|
|
|
|
//Microsoft.Office.Interop.Word.Shape myShape = docWord.Shapes.AddPicture(@"E:\Software-Projekte\OnDoc\Unterschriften\1.jpg", false, true, -50, 0, 120, 50, missing);
|
|
|
//myShape.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapTight;
|
|
|
//myShape.RelativeHorizontalPosition = Microsoft.Office.Interop.Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;
|
|
|
|
|
|
//myShape.Left = horizontal;
|
|
|
//myShape.RelativeVerticalPosition = Microsoft.Office.Interop.Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionPage;
|
|
|
//myShape.Top = vertical - myShape.Height;
|
|
|
////myShape.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoTrue;
|
|
|
//myShape.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapBehind;
|
|
|
//myShape.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendBackward);
|
|
|
//myShape.Select();
|
|
|
|
|
|
|
|
|
|
|
|
// if (imagepath == "") return;
|
|
|
// object missing = Type.Missing;
|
|
|
|
|
|
// Microsoft.Office.Interop.Word.Range myRange1 = docWord.selection this.docWord WordApp.Selection.Range.GoTo(Word.WdGoToItem.wdGoToPage, Word.WdGoToItem.wdGoToPage, 2);
|
|
|
// Microsoft.Office.Interop.Word.Bookmark bm = docWord.Bookmarks[bookmark];
|
|
|
// Microsoft.Office.Interop.Word.Range myRange = docWord.Bookmarks[bookmark].Range;
|
|
|
// float vertical = bm.Range.Information[Microsoft.Office.Interop.Word.WdInformation.wdVerticalPositionRelativeToPage];
|
|
|
// float horizontal = bm.Range.Information[Microsoft.Office.Interop.Word.WdInformation.wdHorizontalPositionRelativeToPage];
|
|
|
// Logging.Logging.Debug("Unterschrift vertical:" + vertical.ToString() + " / Horizontal: " + horizontal.ToString(), "OnDoc", "");
|
|
|
// Microsoft.Office.Interop.Word.Shape myShape = docWord.Shapes.AddPicture(imagepath, false, true,vertical,horizontal, 120, 50, myRange);
|
|
|
// myShape.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapTight;
|
|
|
// myShape.RelativeHorizontalPosition = Microsoft.Office.Interop.Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;
|
|
|
// myShape.RelativeVerticalPosition = Microsoft.Office.Interop.Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionPage;
|
|
|
// myShape.Left = horizontal;
|
|
|
// myShape.Top = (vertical - myShape.Height);
|
|
|
// myShape.Name= "Unterschrift" + "_" + bookmark;
|
|
|
// Logging.Logging.Debug("Myshape:" + myShape.Name + " Left:" + myShape.Left.ToString() + ", Top:" + myShape.Top.ToString(), "OnDoc", "");
|
|
|
//// myShape.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapBehind;
|
|
|
// myShape.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendBackward);
|
|
|
// //myShape.Select();
|
|
|
// return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//object missing = Type.Missing;
|
|
|
//Microsoft.Office.Interop.Word.Range myRange = docWord.Bookmarks[bookmark].Range;
|
|
|
|
|
|
//Microsoft.Office.Interop.Word.Bookmark bm = docWord.Bookmarks[bookmark];
|
|
|
|
|
|
//float vertical = bm.Range.Information[Microsoft.Office.Interop.Word.WdInformation.wdVerticalPositionRelativeToPage];
|
|
|
//float horizontal = bm.Range.Information[Microsoft.Office.Interop.Word.WdInformation.wdHorizontalPositionRelativeToPage];
|
|
|
//vertical = vertical - 50;
|
|
|
|
|
|
//Microsoft.Office.Interop.Word.Shape myshape = docWord.Shapes.AddTextbox(Microsoft.Office.Core
|
|
|
//.MsoTextOrientation.msoTextOrientationHorizontal, (float)horizontal,
|
|
|
//(float)vertical, 120, 50, missing);
|
|
|
//myshape.Name = "Unterschrift" + "_" + bookmark;
|
|
|
//myshape.TextFrame.ContainingRange.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleNone;
|
|
|
//myshape.TextFrame.ContainingRange.Borders.InsideLineStyle = WdLineStyle.wdLineStyleNone;
|
|
|
//myshape.Fill.UserPicture(imagepath);
|
|
|
//myshape.Fill.UserPicture(@"E:\Software-Projekte\OnDoc\Unterschriften\1.jpg");
|
|
|
//myshape.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapBehind;
|
|
|
//myshape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
|
|
|
}
|
|
|
public bool remove_unterschriften_synfusion(string filename)
|
|
|
{
|
|
|
Logging.Logging.Debug("Unterschriften entfernen (Syncfusion)", "OnDoc", filename);
|
|
|
bool is_protected = false;
|
|
|
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
|
|
|
word.NormalTemplate.Saved = true;
|
|
|
word.Documents.Open(filename);
|
|
|
if (word.ActiveDocument.ProtectionType != Microsoft.Office.Interop.Word.WdProtectionType.wdNoProtection)
|
|
|
{
|
|
|
word.ActiveDocument.Unprotect(Password: "Australia");
|
|
|
is_protected = true;
|
|
|
}
|
|
|
remove_unterschriften(ref word, filename);
|
|
|
if (is_protected)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
word.ActiveDocument.Protect(Type: Microsoft.Office.Interop.Word.WdProtectionType.wdAllowOnlyFormFields, NoReset: true, Password: "Australia");
|
|
|
}
|
|
|
catch { }
|
|
|
}
|
|
|
word.ActiveDocument.Save();
|
|
|
word.ActiveDocument.Close();
|
|
|
word.Quit(false);
|
|
|
word = null;
|
|
|
Thread.Sleep(1000);
|
|
|
Logging.Logging.Debug("Ende Unterschriften entfernen (Syncfusion)", "OnDoc", filename);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public bool remove_unterschriften(ref Microsoft.Office.Interop.Word.Application word, string dokumentid)
|
|
|
{
|
|
|
Logging.Logging.Debug("Remove Unterschriften","OnDoc", dokumentid);
|
|
|
|
|
|
bool is_protected = false;
|
|
|
try
|
|
|
{
|
|
|
if (word.ActiveDocument.ProtectionType != Microsoft.Office.Interop.Word.WdProtectionType.wdNoProtection)
|
|
|
{
|
|
|
word.ActiveDocument.Unprotect(Password: "Australia");
|
|
|
is_protected = true;
|
|
|
}
|
|
|
bool found = true;
|
|
|
int i = 1;
|
|
|
while (word.ActiveDocument.Shapes.Count > 0 && found == true)
|
|
|
{
|
|
|
found = false;
|
|
|
if (word.ActiveDocument.Shapes[i].Name.Contains("Unterschrift_"))
|
|
|
{
|
|
|
word.ActiveDocument.Shapes[i].Delete();
|
|
|
found = true;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (is_protected)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
word.ActiveDocument.Protect(Type: Microsoft.Office.Interop.Word.WdProtectionType.wdAllowOnlyFormFields, NoReset: true, Password: "Australia");
|
|
|
}
|
|
|
catch { }
|
|
|
}
|
|
|
Logging.Logging.Debug("Ende Remove Unterschriften", "OnDoc", dokumentid);
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Logging.DocLog.Error("Unterschriften entfernen fehlgeschalgen", "OnDocOffice", dokumentid, "", ex.Message);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public class OfficeToPDF
|
|
|
{
|
|
|
public string word_to_pdf(string dokumentid,string connectionstring,string tempdir)
|
|
|
{
|
|
|
DB db=new DB(connectionstring);
|
|
|
clsdok dok = new clsdok("", "", "", "");
|
|
|
dok = db.GetDocumentAsBase64(dokumentid);
|
|
|
string SQL = "SELECT dbo.dokumenttyp.ErstellungInOffice FROM dbo.dokument INNER JOIN dbo.dokumenttyp ON dbo.dokument.dokumenttypnr = dbo.dokumenttyp.dokumenttypnr where dbo.dokument.dokumentid=@dokumentid";
|
|
|
db.clear_parameter();
|
|
|
db.add_parameter("@dokumentid", dokumentid);
|
|
|
db.Get_Tabledata_Addvar(SQL, false, true);
|
|
|
if (Convert.ToBoolean(db.dsdaten.Tables[0].Rows[0]["Erstellunginoffice"]))
|
|
|
{
|
|
|
return convert_word_to_pdf(ref dok,tempdir,dokumentid);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
DOCGEN.DocGet dg = new DOCGEN.DocGet(connectionstring);
|
|
|
dok = dg.GetDocAsPDF(dokumentid);
|
|
|
dg = null;
|
|
|
return dok.dokument;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public string convert_word_to_pdf(ref clsdok dok,string tempdir,string dokumentid)
|
|
|
{
|
|
|
clsFileHelper fh = new clsFileHelper();
|
|
|
string filename=tempdir+ DateTime.Now.ToString("yyyyMMddhhmmss")+"_"+dokumentid+dok.extension;
|
|
|
string outputfile = filename + ".pdf";
|
|
|
fh.SaveBase64ToFile(dok.dokument, filename);
|
|
|
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
|
|
|
Microsoft.Office.Interop.Word.Document worddoc = new Microsoft.Office.Interop.Word.Document();
|
|
|
worddoc= word.Documents.Open(filename);
|
|
|
worddoc.ExportAsFixedFormat(outputfile.ToString(), Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF, false, Microsoft.Office.Interop.Word.WdExportOptimizeFor.wdExportOptimizeForPrint, Microsoft.Office.Interop.Word.WdExportRange.wdExportAllDocument,0,99, Microsoft.Office.Interop.Word.WdExportItem.wdExportDocumentContent, true, true, Microsoft.Office.Interop.Word.WdExportCreateBookmarks.wdExportCreateNoBookmarks, true, true, false);
|
|
|
|
|
|
worddoc.Close(false);
|
|
|
word.Quit(false);
|
|
|
worddoc = null;
|
|
|
word = null;
|
|
|
return fh.Base64FromFile(outputfile);
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
} |