Click here to Skip to main content
15,886,857 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my Food pantry program, I have a form that lists all the sheets in the excel workbook. When a sheet is selected, I want to show the print dialog before printing a sheet, this is so fit-to-sheet can be selected.

My current code is

 private void cmdPrintSelected_Click(object sender, EventArgs e)
{
        for (int i = 0; i < clbSheetList.Items.Count; i++)
        {
            if (clbSheetList.GetItemChecked(i) == true)
            {
                Excel.Worksheet ws =                 (Excel.Worksheet)frmFoodPantry.theWorkbook.Worksheets[i + 2];
                printSheets(ws);
            }
        }
}


This will print the selected sheet ok, using the default printer, but I would like to give the user the change to select a different printer.

What I have tried:

I have tried the solution in Microsoft Answers.
and
frmFoodPantry.theWorksheet.PageSetup.Zoom = false;
frmFoodPantry.theWorksheet.PageSetup.FitToPagesWide = 1;
//frmFoodPantry.theWorksheet.PageSetup.FitToPagesTall = 1;
frmFoodPantry.theWorksheet.PageSetup.Orientation = Microsoft.Office.Interop.Excel.XlPageOrientation.xlLandscape;
frmFoodPantry.theWorksheet.PageSetup.PaperSize = Microsoft.Office.Interop.Excel.XlPaperSize.xlPaperA4;
printSheets(ws);

I have tried to set the zoom to 50 and commenting out the fitopageswide and tall. The results are the same.
Posted
Updated 1-Aug-22 9:33am
v4

 
Share this answer
 
Comments
PaulaJoannAllen 30-Jul-22 14:36pm    
I looked over that article and managed to get the dialog to show but found no way of setting the print on one page. I also looked over all the printer .net documents and found nothing. I really don't want to make the user to print everything manuly but maybe what I want can't be done. There has to be some way.
Richard MacCutchan 31-Jul-22 2:59am    
I found no way to do that in C#, so I went into the sheets and made the columns as small as practical. They all fit on one sheet now, so the problem is solved. But not the way I was hoping for.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900