Update 20241118

This commit is contained in:
Stefan Hutter
2024-11-18 15:21:58 +01:00
parent 69de21ca51
commit 194a97416c
120 changed files with 635 additions and 61 deletions
+300 -3
View File
@@ -1,5 +1,6 @@
using Microsoft.Office.Interop.Excel;
using Microsoft.Office.Interop.Word;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
@@ -8,6 +9,7 @@ using System.Linq.Expressions;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Office;
namespace OnDocOffice
{
@@ -82,8 +84,11 @@ namespace OnDocOffice
public string connectstring { get; set; }
public string filename { get; set; }
public string dokumentid { get; set; }
public
public bool is_protected { get; set; } = false;
public
Microsoft.Office.Interop.Word.Application word;
Microsoft.Office.Interop.Word.Document worddoc;
Document doc = null;
@@ -94,7 +99,6 @@ namespace OnDocOffice
this.dokumentid = dokumentid;
}
public bool Start_Application()
{
try
@@ -125,7 +129,7 @@ namespace OnDocOffice
{
word.Run(dr[0].ToString());
}
catch ( Exception e) { string a = e.Message;}
catch (Exception e) { string a = e.Message; }
}
}
//clsProcessWatch.AddToList(dokumentid, filename, "Word");
@@ -156,5 +160,298 @@ namespace OnDocOffice
{
}
public string Generate_Word_in_Office(ref clsDocData docdata, ref clsdok dok, string vorlage, string connectionstring, string tempdir, string dokumentid, string apptype)
{
this.dokumentid = docdata.Dokumentid;
string filename = tempdir + dokumentid + "." + apptype;
int pos = 0;
int pos2 = 0;
Helper.clsFileHelper fh = new Helper.clsFileHelper();
fh.SaveBase64ToFile(vorlage, filename);
Start_Application();
worddoc = word.Documents.Open(filename);
if (worddoc.ProtectionType != Microsoft.Office.Interop.Word.WdProtectionType.wdNoProtection)
{
worddoc.Unprotect(Password: "Australia");
is_protected = true;
}
bool cursorpositionieren = false;
if (docdata.Kopfzeile_generieren == true)
{
Kopfzeile_generieren();
}
foreach (clsDocValue dv in docdata.DocValues)
{
try
{
if (dv.TMBeginn.ToString() == "TGEDKCursor" || dv.TMBeginn.ToString() == "TGEDKCursorB" ||
dv.FieldName.ToString() == "TGEDKCursor" || dv.FieldName.ToString() == "TGEDKCursorB") { cursorpositionieren = true; }
}
catch { }
if (dv.TMBeginn.ToString() != "" && dv.TMEnd.ToString() == "")
{
try
{
worddoc.Bookmarks[dv.TMBeginn.ToString()].Select();
word.Selection.Text = dv.Value.ToString();
pos = worddoc.Bookmarks[dv.TMBeginn.ToString()].Start;
pos2 = word.Selection.End;
if (dv.TMBeginn.ToString().Substring(0, 19) == "XTGEDKDirektTelefonB" ||
dv.TMBeginn.ToString().Substring(0, 23) == "XTGEDKVornameNameBetreue" ||
dv.TMBeginn.ToString().Substring(0, 19) == "XTGEDKDirektTelefonZ")
{
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;
}
else
{
if (dv.TMBeginn.ToString().Substring(0, 22) == "XTGEDKDirektTelefonDokZ" ||
dv.TMBeginn.ToString().Substring(0, 20) == "XTGEDKVornameNameDokZ")
{
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;
}
else
{
//objWord.Visible = True
// objWord.Selection.SetRange(Start:= pos, End:= pos2)
// With docWord.Bookmarks
// .Add(Range:= objWord.Selection.Range, Name:= Dokumentdaten.Rows(i).Item("beginntextmarke"))
// .DefaultSorting = Microsoft.Office.Interop.Word.WdBookmarkSortBy.wdSortByName
// .ShowHidden = False
// End With
}
}
//objWord.Selection.MoveLeft(Unit:= Microsoft.Office.Interop.Word.WdUnits.wdCharacter, Count:= 1)
// objWord.Selection.MoveLeft(Unit:= Microsoft.Office.Interop.Word.WdUnits.wdCharacter, Count:= 2, Extend:= Microsoft.Office.Interop.Word.WdMovementType.wdExtend)
// If objWord.Selection.Text = " " Then
// objWord.Selection.MoveRight(Unit:= Microsoft.Office.Interop.Word.WdUnits.wdCharacter, Count:= 1)
// objWord.Selection.MoveLeft(Unit:= Microsoft.Office.Interop.Word.WdUnits.wdCharacter, Count:= 1, Extend:= Microsoft.Office.Interop.Word.WdMovementType.wdExtend)
// objWord.Selection.Delete(Unit:= Microsoft.Office.Interop.Word.WdUnits.wdCharacter, Count:= 1)
// End If
}
catch { }
}
if (dv.TMBeginn.ToString() != "" && dv.TMEnd.ToString() != "")
{
try
{
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());
}
catch { }
}
if (dv.FieldName.ToString() != "")
{
try
{
worddoc.FormFields[dv.FieldName.ToString()].Result = dv.Value;
}
catch { }
}
}
if (docdata.Barcode == true) { Generate_Barcodes(ref docdata); }
if (is_protected)
{
worddoc.Protect(Type: Microsoft.Office.Interop.Word.WdProtectionType.wdAllowOnlyFormFields, NoReset: true, Password: "Australia");
}
worddoc.Save();
worddoc.Close();
word.Quit(SaveChanges: false);
worddoc = null;
word = null;
return fh.Base64FromFile(filename);
}
private void Kopfzeile_generieren()
{
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;
}
}
private void Generate_Barcodes(ref clsDocData docdata)
{
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();
word.Selection.GoTo(What:Microsoft.Office.Interop.Word.WdGoToItem.wdGoToPage,xname);
HeaderFooterAnzeigen();
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;
}
}
}
+15
View File
@@ -44,6 +44,11 @@
<EmbedInteropTypes>True</EmbedInteropTypes>
<HintPath>..\..\..\EDOKA\Cleint_Erneuerung_DMS_Framwork48 - Kopie\EDOKA\bin\Microsoft.Office.Interop.Word.dll</HintPath>
</Reference>
<Reference Include="Office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<EmbedInteropTypes>True</EmbedInteropTypes>
<HintPath>..\..\..\EDOKA\Cleint_Erneuerung_DMS_Framwork48\EDOKA\bin\Office.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
@@ -57,5 +62,15 @@
<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Helper\Helper.csproj">
<Project>{216c1660-5ad5-4a5e-80e4-150ccf673cbc}</Project>
<Name>Helper</Name>
</ProjectReference>
<ProjectReference Include="..\Model\Model.csproj">
<Project>{a1fd0973-89a7-4588-877d-373835d6e00c}</Project>
<Name>Model</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
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.
@@ -1 +1 @@
534cb9f9eb736773911e11df7d43aef46ba5cd45c1563474a33f08d0a375e179
965fd7818a4fbf445c4e84fc30d9b03b23e7b2a5316a7be82fa6d22dc71f07d2
Binary file not shown.
Binary file not shown.