views:

26

answers:

0

I'm using C# and the Office 2007 Excel Interop library. I'm needing to adjust the print quality of every page on each worksheet in an Excel file using the Interop API.

The following is my current code for doing this. This is happening within a foreach loop over every Worksheet in the Workbook.

        // Attempt to force the printer to use 300 dpi quality
        Int32 quality_x = Int32.Parse("" + Worksheet.PageSetup.get_PrintQuality(1));
        Int32 quality_y = Int32.Parse("" + Worksheet.PageSetup.get_PrintQuality(2));
        if (quality_x != 200 || quality_y != 200)
        {
            try
            {
                object[] y = new Object[] { 200, 200 };
                Worksheet.PageSetup.set_PrintQuality(y, Type.Missing);

                Console.WriteLine("Print quality adjusted from {0}x{1} to {2}x{3}", quality_x, quality_y,
                                                                                    (int)Worksheet.PageSetup.get_PrintQuality(1),
                                                                                    (int)Worksheet.PageSetup.get_PrintQuality(2));
            }
            catch (Exception)
            {
                Console.WriteLine("Unable to adjust print quality for {0}", Worksheet.Name);
            }
        }

The thing is, though, is that it's not changing the DPI. It says "Adjusted from 600x600 to 600x600", even though I specified 300x300. I know the printer supports 300x300. And, sometimes it says it is unable to adjust the print quality.

The set_printquality method is so poorly documented that I was only able to find 1 vague reference to it through forum comments on a small forum on like the 3rd page of google results. Am I using this method incorrectly? How can I set the print quality to be the same for every page, in every worksheet for an entire workbook?

Thank you, Ryan