我试图导出一个Excel文件到PDF,但alignment是否正在closures?

导出纸张时,alignmentclosures。 一半数据在下一行。 我如何以编程方式alignment工作表,并将其转换为pdf,而不需要alignment。

我需要一些适合页面的东西。

PDF的宽度取决于您的Excel打印设置,默认情况下,它将设置为A4人像,所以导出的PDF将半数据保留到下一行; 如果将纸张尺寸设置为A3横向,然后导出为PDF,则会显示正确的格式。

我遇到了同样的问题,所以我做了:

  1. 为Excel文件表我设置以下

    xlWorkbook = xlApps.Workbooks.Add(missing); xlWorkSheet = (Excel.Worksheet)xlWorkbook.Worksheets.get_Item(1); xlApps.ActiveWindow.View = Excel.XlWindowView.xlPageLayoutView; //pagelayout view xlWorkSheet.PageSetup.PaperSize = Excel.XlPaperSize.xlPaperA4; //set paper to A4 xlWorkSheet.PageSetup.Orientation = Excel.XlPageOrientation.xlPortrait; //set to portrait //margins 'Narrow' xlWorkSheet.PageSetup.LeftMargin = 0.65; //55 xlWorkSheet.PageSetup.RightMargin = 0.25; xlWorkSheet.PageSetup.BottomMargin = 0.75; xlWorkSheet.PageSetup.TopMargin = 0.75; //60 xlWorkSheet.PageSetup.HeaderMargin = 0; 
  2. 转换我的Excel文件并缩放大小。 (只需更改120以适合您的文档)

      //here is the scaling Worksheet xlmsheet = excelWorkBook.Sheets[1]; xlmsheet.PageSetup.Zoom = 120; // Save it in the target format. if (excelWorkBook != null) excelWorkBook.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, paramExportFilePath, XlFixedFormatQuality.xlQualityStandard, true, true, Type.Missing, Type.Missing, false, paramMissing); 

为什么不使用FitToPagesWide和FitToPagesTall

  xlWorkSheet.PageSetup.Zoom = False xlWorkSheet.PageSetup.FitToPagesWide = 1 xlWorkSheet.PageSetup.FitToPagesTall = 1