updage 20241230

master
Stefan Hutter 12 months ago
parent 2feaf6cc29
commit 238ef660aa

Binary file not shown.

Binary file not shown.

@ -263,7 +263,15 @@ namespace OnDoc.UIControls
ExcelNet.ExcelReader reader = new ExcelNet.ExcelReader();
string selected_sheetname = "";
var sheets = new List<string>();
sheets = reader.Get_ExcelSheets(openFileDialog1.FileName);
try
{
sheets = reader.Get_ExcelSheets(openFileDialog1.FileName);
}
catch {
MessageBox.Show("Auf die gewählte Excel-Datei kann aktuell nicht zugegriffen werden. Evtl. ist diese noch geöffnet.", "Excel-Import", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (sheets.Count > 1)
{
DocMgmt.Serienbrief_Sheetselect sheetselect = new DocMgmt.Serienbrief_Sheetselect(sheets);
@ -1022,6 +1030,7 @@ namespace OnDoc.UIControls
string check_duplicates = "";
foreach (var dup in duplicates)
{
set_grid_color(dup.ToString());
if (check_duplicates != "") { check_duplicates = check_duplicates + ", "; }
check_duplicates = check_duplicates + dup.ToString();
}
@ -1045,6 +1054,11 @@ namespace OnDoc.UIControls
return true;
}
private void set_grid_color(string partner)
{
}
private void check_zwingende_felder()
{
@ -1661,7 +1675,7 @@ namespace OnDoc.UIControls
PdfDocument finalDoc = new PdfDocument();
DB db = new DB(AppParams.connectionstring);
int stapelgroesse = 100;
int stapelgroesse = 200;
int stapel = 1;
int i = 0;
int anzahl_stapel = (dv.Count / 100) + 1;
@ -1681,10 +1695,14 @@ namespace OnDoc.UIControls
if (i >= stapelgroesse)
{
save_stapel(stapel, ref streams);
i = 0;
streams = new Stream[dv.Count - (stapel * stapelgroesse)];
stapel++;
if (dv.Count-(stapel * stapelgroesse) >= stapelgroesse) { streams = new Stream[stapelgroesse]; } else
{
streams = new Stream[dv.Count - (stapel * stapelgroesse)];
}
//streams = new Stream[dv.Count - (stapel * stapelgroesse)];
stapel++;
}
}
}
@ -1725,9 +1743,13 @@ namespace OnDoc.UIControls
treeviewDruckstapel.Nodes.Add(tn);
for (int i = 0; i < streams.Length; i++)
{
streams[i].Close();
streams[i].Dispose();
streams[i] = null;
}
streams = null;
finalDoc = null;
}
catch { }
}

@ -79,8 +79,8 @@ namespace OnDoc.Klassen
EDOKAPath = db.dsdaten.Tables[0].Rows[0][12].ToString();
OfficeSpleep1 = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0][13]);
OfficeSpleep2 = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0][14]);
pathNativVorlagen = db.dsdaten.Tables[0].Rows[0][15].ToString();
Office_Fill_DocIO= Convert.ToInt32(db.dsdaten.Tables[0].Rows[0][15]);
pathNativVorlagen = db.dsdaten.Tables[0].Rows[0][16].ToString();
Office_Fill_DocIO= Convert.ToInt32(db.dsdaten.Tables[0].Rows[0][17]);
}
else
{

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -160,16 +160,17 @@ namespace DOCGEN.Klassen
MemoryStream ms = new MemoryStream(Helper.EncodeExtensions.DecodeBase642ByteArray(base64));
WordDocument document = new WordDocument(ms, FormatType.Automatic);
CompatibilityMode compatibilityMode = document.Settings.CompatibilityMode;
Logging.Logging.Debug(compatibilityMode.ToString(), "ondoc sf", docdata.Dokumentid);
switch (compatibilityMode)
{
case CompatibilityMode.Word2010:
document.Settings.CompatibilityMode = CompatibilityMode.Word2010;
break;
case CompatibilityMode.Word2013:
document.Settings.CompatibilityMode = CompatibilityMode.Word2013;
break;
default:
document.Settings.CompatibilityMode = CompatibilityMode.Word2003;
//document.Settings.CompatibilityMode = CompatibilityMode.Word2003;
break;
}
//if (compatibilityMode == CompatibilityMode.Word2010) { document.Settings.CompatibilityMode = CompatibilityMode.Word2010; }
@ -308,6 +309,7 @@ namespace DOCGEN.Klassen
{
bookmarkNavigator.MoveToBookmark(dv.TMBeginn.ToString());
bookmarkNavigator.InsertText(dv.Value.ToString());
bookmarkNavigator.ReplaceBookmarkContent(dv.Value.ToString(), true);
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -287,11 +287,13 @@ namespace DOCGEN
public string Convert_Word_To_PDF(string document, DataTable pdfparameters = null, bool useseettings = false)
{
//Dokument erstellen
var streamword = new MemoryStream(Convert.FromBase64String(document));
WordDocument wordDocument = new WordDocument(streamword, Syncfusion.DocIO.FormatType.Automatic);
// Keine Parameter / Dokument als PDF konvertieren
if (pdfparameters == null)
{

Binary file not shown.

Binary file not shown.

@ -11,7 +11,7 @@ namespace ExcelNet
{
public class ExcelReader
{
public List<string> Get_ExcelSheets(string filename)
{

@ -113,9 +113,13 @@ namespace FastExcel {
_templateFile = templateFile;
_excelFile = excelFile;
TemplateFileStream = templateFile != null ? new FileStream(templateFile.FullName, FileMode.Open, FileAccess.Read) : null;
ExcelFileStream = updateExisting
? new FileStream(excelFile.FullName, FileMode.Open, readOnly ? FileAccess.Read : FileAccess.ReadWrite)
: new FileStream(excelFile.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
try
{
ExcelFileStream = updateExisting
? new FileStream(excelFile.FullName, FileMode.Open, readOnly ? FileAccess.Read : FileAccess.ReadWrite)
: new FileStream(excelFile.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
}
catch { }
UpdateExisting = updateExisting;
ReadOnly = readOnly;

@ -75,6 +75,10 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="VBFileManagement, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\VBFileManagement\bin\Debug\VBFileManagement.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="clsoffice.cs" />

@ -20,6 +20,7 @@ using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using System.IO;
using Microsoft.VisualBasic;
using System.Net.NetworkInformation;
namespace OnDocOffice
{
@ -275,9 +276,14 @@ namespace OnDocOffice
{
try
{
word = new Microsoft.Office.Interop.Word.Application();
word.Run("Autoexec");
word.NormalTemplate.Saved = true;
//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
@ -286,6 +292,7 @@ namespace OnDocOffice
}
}
public void Edit_Document(bool runmacros)
{
Start_Application();
@ -350,6 +357,53 @@ namespace OnDocOffice
}
}
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 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 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)
{
this.dokumentid = docdata.Dokumentid;
@ -357,85 +411,94 @@ namespace OnDocOffice
int pos = 0;
int pos2 = 0;
VBFileManagement.VBFileManagement vb = new VBFileManagement.VBFileManagement();
vb.Get_From_DB(Convert.ToInt32(docdata.VorlageNr), filename, connectionstring, false);
Helper.clsFileHelper fh = new Helper.clsFileHelper();
vorlage = fh.Base64FromFile(filename);
vorlage = set_cmode(vorlage);
fh.SaveBase64ToFile(vorlage, filename);
Logging.Logging.Debug("Generate_Word_in_Office", "clsOffice", dokumentid);
Start_Application();
Logging.Logging.Debug("Ende Start_Application", "clsOffice", dokumentid);
// Thread.Sleep(OfficeSleep);
worddoc = word.Documents.Open(filename);
Thread.Sleep(OfficeSleep);
string ext = System.IO.Path.GetExtension(filename).ToUpper();
switch (word.ActiveDocument.CompatibilityMode)
{
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;
}
Logging.Logging.Debug("Word Open", "clsOffice", dokumentid);
Logging.Logging.Debug(word.ActiveDocument.CompatibilityMode.ToString(), ext, dokumentid);
//switch (word.ActiveDocument.CompatibilityMode)
//{
// 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;
//}
word.NormalTemplate.Saved = true;
//word.ActiveDocument.Close(false);
Thread.Sleep(OfficeSleep);
//worddoc = word.Documents.Open(filename);
Logging.Logging.Debug("Word Open", "clsOffice", dokumentid);
Logging.Logging.Debug("Word befüllen", "clsOffice", dokumentid);
Thread.Sleep(OfficeSleep);
if (worddoc.ProtectionType != Microsoft.Office.Interop.Word.WdProtectionType.wdNoProtection)
{
worddoc.Unprotect(Password: "Australia");
@ -573,12 +636,17 @@ namespace OnDocOffice
if (is_protected)
{
worddoc.Protect(Type: Microsoft.Office.Interop.Word.WdProtectionType.wdAllowOnlyFormFields, NoReset: true, Password: "Australia");
try
{
worddoc.Protect(Type: Microsoft.Office.Interop.Word.WdProtectionType.wdAllowOnlyFormFields, NoReset: true, Password: "Australia");
}
catch { }
}
//word.Visible = true;
Logging.Logging.Debug("Start Macros", "clsOffice", dokumentid);
run_macros(ref docdata, connectionstring);
worddoc.Save();
Logging.Logging.Debug("Word Saved", "clsOffice", dokumentid);
@ -932,6 +1000,22 @@ namespace OnDocOffice
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)
{
if (docdata.Form_ohne_Unterschrift == "True")
@ -1025,8 +1109,18 @@ namespace OnDocOffice
}
else
{
bookmarkNavigator.MoveToBookmark(dv.TMBeginn.ToString());
bookmarkNavigator.InsertText(dv.Value.ToString());
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;
}
}
}

@ -1 +1 @@
eb32d9bf6208a44886b912603a96aa2b1a08a09956beecde6f8f08a4d00296ba
884c6102be53750b3d358cc632173bd7eedf7e2f767ce1a2dcb3e182bfc74fa2

Loading…
Cancel
Save