Created
August 12, 2019 14:15
-
-
Save bjoerntx/57047cc54171708fd802976719bdb2bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void MailMerge_IncludeTextMerging(object sender, | |
TXTextControl.DocumentServer.MailMerge.IncludeTextMergingEventArgs e) | |
{ | |
// custom handing of XLSX files | |
switch (Path.GetExtension(e.IncludeTextField.Filename)) | |
{ | |
case ".xlsx": // Excel file detected | |
if (!File.Exists(e.IncludeTextField.Filename)) | |
return; | |
// load document into temp. ServerTextControl | |
using (TXTextControl.ServerTextControl tx = | |
new TXTextControl.ServerTextControl()) | |
{ | |
tx.Create(); | |
// Bookmark name is the sheet name of the Excel document | |
TXTextControl.LoadSettings ls = new TXTextControl.LoadSettings() | |
{ | |
DocumentPartName = e.IncludeTextField.Bookmark | |
}; | |
try | |
{ | |
// load the Excel document | |
tx.Load( | |
e.IncludeTextField.Filename, | |
TXTextControl.StreamType.SpreadsheetML, | |
ls); | |
} | |
catch { | |
return; | |
} | |
byte[] data; | |
// save the document using the TX format | |
tx.Save(out data, | |
TXTextControl.BinaryStreamType.InternalUnicodeFormat); | |
e.IncludeTextDocument = data; // pass back to the field | |
} | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment