关于打印设置的一些问题

问题1:PageSetup.PrintCopies 这个设置打印份数,我设置了,但是实际打印中无效
代码如下: Dim PageSetup As PageSetup = 表.PageSetup
PageSetup.PaperSize = PaperSizeType.PaperA4
PageSetup.PrintGridlines = True
PageSetup.SetHeader(0, “&D”)
PageSetup.CenterHorizontally = True '是否水平居中打印
PageSetup.CenterVertically = True '是否垂直居中打印
PageSetup.Orientation = PageOrientationType.Portrait '横向
PageSetup.PrintArea = “A1:G16” '打印范围
PageSetup.PrintCopies = 2 '打印份数
问题2:关于PageSetup.PrinterSettings = 这个方法属性不知道怎么用,请举个例子,是要把微软的PrinterSettings类反序列化吗?还是 怎么使用

@222103,

感谢您的查询。

1)请提供更多详细信息和示例文件。一些截图可以很好地突出打印输出中的问题。

2)请参考示例代码以供参考:
例如
示例代码:

'Your code goes here.
'........
Dim ws As Worksheet = workbook.Worksheets(0)
Dim printerSettings As System.Drawing.Printing.PrinterSettings = New System.Drawing.Printing.PrinterSettings()
Dim strPrinterName As string = printSettings.PrinterName

'printing Worksheet
Dim options As Aspose.Cells.Rendering.ImageOrPrintOptions = New Aspose.Cells.Rendering.ImageOrPrintOptions()
options.PrintingPage = PrintingPageType.Default
Dim sr As Aspose.Cells.Rendering.SheetRender = new Aspose.Cells.Rendering.SheetRender(ws, options)
sr.ToPrinter(strPrinterName)

我希望这可以帮助你。

代码 : Dim PageSetup As PageSetup = 表.PageSetup
PageSetup.PaperSize = PaperSizeType.PaperA4
PageSetup.PrintGridlines = True
PageSetup.SetHeader(0, “&D”)
PageSetup.CenterHorizontally = True '是否水平居中打印
PageSetup.CenterVertically = True '是否垂直居中打印
PageSetup.Orientation = PageOrientationType.Portrait '横向
PageSetup.PrintArea = “A1:G16” '打印范围
PageSetup.PrintCopies = 2 '打印份数
PageSetup.PrintQuality = 1200 '打印质量
Dim ImageOrPrintOptions As Aspose.Cells.Rendering.ImageOrPrintOptions = New Aspose.Cells.Rendering.ImageOrPrintOptions() '工作表渲染到图像,打印工作表或将图表渲染到图像时指定选项。
’ ImageOrPrintOptions.HorizontalResolution = 600 '默认96
ImageOrPrintOptions.ChartImageType = System.Drawing.Imaging.ImageFormat.Jpeg
ImageOrPrintOptions.ImageType = Drawing.ImageType.Jpeg
ImageOrPrintOptions.Quality = 100
ImageOrPrintOptions.VerticalResolution = 1200
ImageOrPrintOptions.HorizontalResolution = 1200
ImageOrPrintOptions.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
ImageOrPrintOptions.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit
Dim SheetRender As Aspose.Cells.Rendering.SheetRender = New Aspose.Cells.Rendering.SheetRender(表, ImageOrPrintOptions)
Dim PrinterSettings As New System.Drawing.Printing.PrinterSettings()
Dim 打印机名称 As String = PrinterSettings.PrinterName
SheetRender.ToPrinter(打印机名称)

另外关于第2个问题,您还没有回答我
问题2:关于PageSetup.PrinterSettings =这个方法属性不知道怎么用,请举个个子子,是要把微软的PrinterSettings类反序列化吗?还是怎么使用

@222103,

1)还请提供模板Excel文件和输出打印输出(您可以将打印保存为图像或PDF),以便我们可以使用您的代码段和模板文件来评估您的问题。

2)似乎PageSetup.PrinterSettings属性没有太大用处。您应该尝试使用SheetRender API将其发送到打印机,如我们之前的回复中的示例代码所述。在任何情况下,我们仍将检查并回复您的更多详细信息和示例以及PageSetup.PrinterSettings。

33.png (647 Bytes)
11.png (10.8 KB)
22.png (24.7 KB)
2.Jpeg (914.5 KB)

您应该尝试使用SheetRender API将其发送到打印机:
SheetRender 也查过相关API,没有找到相关例子,请举例 如何将设置传递到SheetRender

@222103,

谢谢你的图像文件。

您似乎关注PrintCopies。我们有一个API:WorkbookRender.ToPrinter(PrinterSettings PrinterSettings),您可以在此PrinterSettings对象中设置打印机的副本。
例如
示例代码:

Workbook wb = new Workbook(TMP_DIR + "test.xlsx");

            ImageOrPrintOptions imgOpt = new ImageOrPrintOptions();

            WorkbookRender bookRender = new WorkbookRender(wb, imgOpt);
            PrinterSettings printerSettings = new PrinterSettings();
            printerSettings.PrinterName = "Microsoft Print to PDF";
            printerSettings.Copies = 2;

            bookRender.ToPrinter(printerSettings);

这是测试用例的源文件和附加文件。
files1.zip (50.6 KB)

如有必要,我们还可以在SheetRender API下添加API“ToPrinter(PrinterSettings PrinterSettings)”,请确认您是否需要它?

@222103,

此外,关于PageSetup.PrinterSettings API,它返回字节数组。此API用于获取和设置用户请求的默认打印机设置。例如,如果要将其替换为预设模板文件中打印机的默认设置。请参阅示例代码段以供参考:
例如
示例代码:

Workbook template = new Workbook(dir + "template.xlsx");
            Workbook workbook = new Workbook();
            workbook.Worksheets[0].PageSetup.PrinterSettings = template.Worksheets[0].PageSetup.PrinterSettings;
........

希望这个对你有帮助。

用你这例子打印份数增加了,但是这个是打印整个工作薄的,可以在SheetRender API下添加ToPrinter(PrinterSettings PrinterSettings)谢谢

顺带问下 WorkbookRender. CustomPrint 方法,这个方法如何使用,第二个参数,printPageEventArgs 这个参数如何设置

@222103,

我根据您的要求/问题录制了ID为“CELLSNET-46877”的机票。我们会尽快调查以支持它。
更新后我们会通知您。

我们将提供更多详细信息和示例代码供您参考。

@222103,

请参阅代码段以测试API:WorkbookRender。 CustomPrint供您参考:
例如
示例代码:

public class TestCustomPrint
    {
        private WorkbookRender bookRender;
        private ImageOrPrintOptions imgOpt;
        private bool nextPageAfterPrint;
        public TestCustomPrint(string filePath)
        {
            Workbook wb = new Workbook(filePath);

            imgOpt = new ImageOrPrintOptions();

            bookRender = new WorkbookRender(wb, imgOpt);

            nextPageAfterPrint = true;

        }

        private void CustomPrintPageEventHandler(object sender, PrintPageEventArgs e)
        {
            int pageIndex = bookRender.CustomPrint(nextPageAfterPrint, e);

            if(nextPageAfterPrint && pageIndex == 1)
            {
                //repeat the second page(page index = 1)
                nextPageAfterPrint = false;
            }
            else
            {
                nextPageAfterPrint = true;
            }

            if(pageIndex == 1)
            {
                //Page layout orientation Landscape.
                e.PageSettings.Landscape = true;
            }
            else
            {
                e.PageSettings.Landscape = false;
            }

            if(pageIndex < bookRender.PageCount)
            {
                e.HasMorePages = true;
            }
        }

        public void ToPrinter()
        {
            imgOpt.CustomPrintPageEventHandler = CustomPrintPageEventHandler;

            PrinterSettings printerSettings = new PrinterSettings();
            printerSettings.PrinterName = "Microsoft Print to PDF";
            printerSettings.Copies = 2;

            bookRender.ToPrinter(printerSettings);
        }


    }

........
TestCustomPrint testCustomPrint = new TestCustomPrint(TMP_DIR + "test.xlsx");

            testCustomPrint.ToPrinter();
........

打印每页时,您可以控制打印机的页面设置。示例代码仅更改第二页的页面设置(页面索引为1)。

我希望这可以帮助你。

看明白了,谢谢,有时间我测试下,有问题在问您,在此感谢你们热心的回答

@222103,

我很高兴知道您现在已经了解了API。如果您仍然发现任何问题,请随时发布您的示例代码,模板文件和屏幕截图。我们会尽快检查。

@222103,

请尝试我们的最新版本/修复:Aspose.Cells for .NET v19.8.4(附)

你的问题应该解决它。添加了一个新的API SheetRender.ToPrinter(PrinterSettings PrinterSettings)。

请告诉我们您的反馈意见。
Aspose.Cells19.8.4 For .Net2_AuthenticodeSigned.Zip (4.9 MB)
Aspose.Cells19.8.4 For .Net4.0.Zip (4.9 MB)

The issues you have found earlier (filed as CELLSNET-46877) have been fixed in Aspose.Cells for .NET v19.9. This message was posted using BugNotificationTool from Downloads module by Amjad_Sahi