Skip to content
foglcz edited this page Apr 22, 2013 · 10 revisions

Printer settings in Excel are also fairly easy. The API generates none by default - when dealing with page setup, most of that will end up in some kind of a tag by the end of your <worksheet> tag anyway.

However, there are times when you need to generate properly set-up worksheets, eg. for stock labels printing. What we're talking about is actually a printer-dependent settings, which you need to preserve within the generated sheet.

The printer-dependent settings are repsesenter by a binary file and therefore it's un-createable from XSLT itself. What we do is completely different procedure:

  • the default worksheet you want to use for extracting the data, MUST be created on the end machine and under the windows user, for whom you want these settings preserved.
  • in order to have the printer settings saved, you do need to print the excel file at least once - and save it afterwards
  • before you start working on the actual implementation, re-check all dimensions & printout just by plain open, print, close&dontsave procedure done under the final user on the final machine.

There's couple of reasons for this process. Namely; when you're facing this issue, you're probably doing something, that prints eg. barcodes. And you're probably doing it for one or two people in the company - or just their user accounts on remote services server.

The reason for doing it under respective user account is that, the binary file probably contains settings for every single printer installed. And it probably saves those printers by their index - therefore, settings on dev machine will not ever match the production deployment.

All of the above statements is assumption based on personal experience. If someone could enlighten this, we would be glad - but the process we're using seems bullet-proof.

Appending the binary file into excel file

OK, so you have template. All you need to do now is to pass the filename to Excel engine:

<xsl:with-param name="printerSettings"><setting for="1">Sheet_PrinterSettings.bin</setting></xsl:with-param>

The @for attribute specifies id of the sheet (position() of <worksheet> node), where this particular printer settings will be used.

However, the engine cannot modify your markup, therefore, you have to reference the respective printer settings within the <worksheet> tag:

<pageSetup r:id="rId2" paperSize="9" scale="70" fitToHeight="10000" orientation="landscape"/>

Note the r:id parameter. The value, for printer settings, is always rId2 .

Don't panic if you don't have printerSettings.bin file. The <pageSetup> can be specified without the r:id attribute - effectively having the page set-up, but without those advanced 'features'.

Navigation

  1. Preparing excel files
  2. Preparing the first output
  3. Putting plain data into excel sheet
  4. Appending images
  5. Creating multiple worksheets
  6. Printer settings
  7. Macro-enabled workbooks
  8. Under the hood
  9. Engine parameters documentation
  10. Best practice for writing Excel XML
  11. Authors, license, contributing