We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Excel - Set Active Printer

For Excel how do we set a Active Printer or Set Paper Size as ID Card Size. Want to use Printer other than Default Printer.
Size Details:
ISO ID-1 
In MM (85.60 X 53.98 MM)
In Points (242.65 X 153.02)
In Inch (2.13" X 3.38")

Output PDF Conversion needs to be this ID Card Size. If we don't change the Active Printer of Excel before conversion then PDF is coming full default A4 size. 
We can do this in excel, but how we do in XLsIO
Dim excel As Microsoft.Office.Interop.Excel.Application
excel = New Microsoft.Office.Interop.Excel.Application
excel.ActivePrinter = _DEFAULT_ID_PRINTER
wb.Activate()
wb.Save()
Thanks & Best Regards,

3 Replies

KD Kesavan D Syncfusion Team June 2, 2016 05:12 AM UTC

Hi Nilofer, 

Thank you for contacting Syncfusion support. 

Regarding query related to setting Paper Size. 

XlsIO has support for setting the page size using PaperSize property in IWorksheet.PageSetup. Even though when a different page size is set, while printing the document the page size is overridden by the page setting of printer which is chosen(This overriding behavior is seen in Microsoft Excel also).  

Regarding query related to changing Active Printer 

Currently, XlsIO does not have support to change active printer or printing a document, but as a workaround you can use the below code to print the XlsIO generated document to your desired printer( which already has the required ISO ID-1 paper size as its default one)

        [DllImport("Winspool.drv")] 
        private static extern bool SetDefaultPrinter(string printerName); 
 
        static void Main(string[] args) 
        { 
            // Change the default printer to XPS Document Writer 
            SetDefaultPrinter("Microsoft XPS Document Writer"); 
 
            //Print an Excel document 
            System.Diagnostics.Process pr = new System.Diagnostics.Process(); 
            pr.StartInfo.Verb = "Print"; 
            pr.StartInfo.FileName = "Sample.xls"; 
            pr.Start(); 
        } 

Please let us know if you any further queries. 

Regards, 
Kesavan


NI Nilofer June 19, 2016 09:08 AM UTC

Thanks Kesavan D, will look into this.


KD Kesavan D Syncfusion Team June 20, 2016 04:44 AM UTC

Hi Nilofer, 

Thanks for the update. 

We are waiting to hear the testing results from you. 

Kesavan 


Loader.
Up arrow icon