The Worksheet.PageSetup properties are extremely slow when you set them, but are very fast to simply get a value.
Therefore, the best approach is to check each value first, to make sure that you need to set it, and then only set the properties that you need. In addition, it can help to set 'Application.ScreenUpdating = False' and 'Application.Calculation = xlCalculationManual'.
Using your code as a starting point, the updated code could look something like this:
Excel.Application excelApp = xlWS.Application;
bool origScreenUpdating = excelApp.ScreenUpdating;
Excel.XlCalculation origCalcMode = excelApp.Calculation;
try
{
myExcelApp.ScreenUpdating = False;
myExcelApp.Calculation = xlCalculationManual;
xlWS.Name = "INVOICE";
if (xlWS.PageSetup.PaperSize != XlPaperSize.xlPaperA4)
{
xlWS.PageSetup.PaperSize = XlPaperSize.xlPaperA4;
}
if (xlWS.PageSetup.TopMargin != xl.CentimetersToPoints(1.5))
{
xlWS.PageSetup.TopMargin = xl.CentimetersToPoints(1.5);
}
if (xlWS.PageSetup.LeftMargin != xl.CentimetersToPoints(1))
{
xlWS.PageSetup.LeftMargin = xl.CentimetersToPoints(1);
}
if (xlWS.PageSetup.BottomMargin != xl.CentimetersToPoints(1.5))
{
xlWS.PageSetup.BottomMargin = xl.CentimetersToPoints(1.5);
}
if (xlWS.PageSetup.RightMargin != xl.CentimetersToPoints(1))
{
xlWS.PageSetup.RightMargin = xl.CentimetersToPoints(1);
}
if (xlWS.PageSetup.Zoom != 60)
{
xlWS.PageSetup.Zoom = 60;
}
}
finally
{
myExcelApp.ScreenUpdating = origScreenUpdating;
myExcelApp.Calculation = origCalcMode;
}
This is the best that you can do on the Excel side of things -- and it usually helps a lot. I'm less certain how much this will help in your situation, however, as it appears that you might be making a lot of setting changes that differ from the default. Therefore, first checking that the value needs to be made might not help you if all these changes do, in fact, need to occur.
But I have my fingers crossed for you...
-- Mike
(By the way, for cross reference, here's a VBA answer I gave on the same topic where the OP saw a nice performance improvement: How to print faster in Excel VBA?)