Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created August 12, 2019 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/57047cc54171708fd802976719bdb2bd to your computer and use it in GitHub Desktop.
Save bjoerntx/57047cc54171708fd802976719bdb2bd to your computer and use it in GitHub Desktop.
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