0

I'm currently working on a C# 2010 service that collects a text file from a folder, creates an Excel file from it and saves this file. The txt data is correctly read, processed and the Excel files is stored as it should. However, I need to add print ranges in the excel sheet. This is where my service returns an exception.

The problem probably is that a service runs underneath the system account. Since a printer (that is not shared) is user dependent, meaning the system account wont have printers installed.

To implement this, how can I do this? - How can the service add a printer to the system account? - Would it work with the Microsoft XPS printer? - If it cannot be done by the XPS printer, how can I add another printer. We don't have a print server, so everyone has to install the drivers locally for the network printer. How can I add a (network) printer to the system account and use the correct driver?

The excel files are created on and printed from the same computer. Creation is underneath the system account, printing underneath a user account.

Thanx in advance!!!

Jan

Jan Solo
  • 183
  • 1
  • 8
  • 19

1 Answers1

0

In the end I solved the problem like this:

The excel file:

  • I created an excel file that has no data in it and one macro
  • The macro runs only when there is data in the sheet (if cell x = empty then exit sub)
  • The macro sets print ranges correct

The service:

  • Service opens the excel file
  • Adds the data
  • Service saves a copy of the original file (meaning the original file stays untouched)

Due to security it is not very recommended to let the system account add a macro to excel (which is entirely possible, but you have to change the excel default security for all users). So that is why we have chosen to use an excel file that contained a macro.

Jan Solo
  • 183
  • 1
  • 8
  • 19