在忽略比例的情况下,使用Matlab将Excel文件转换为PDF

在忽略比例的情况下,使用Matlab将Excel文件转换为PDF,excel,matlab,pdf,Excel,Matlab,Pdf,我想使用Matlab将Excel文件转换为PDF。Excel文件由一个表格和一个图形填充。它们占用的空间比DIN A4页面大,因此当我使用以下代码时,我的Excel文件在PDF中被“分割”成几页。我想问一下,是否以及如何能够在一页上缩放PDF中的输出,或者忽略缩放,以便表格完全在一页上,而下面的图形则在一页上。也许将打印属性更改为仅一页会有所帮助。在Matlab中可以这样做吗 守则: hExcel = actxserver('Excel.Application'); hWorkbook = hE

我想使用Matlab将Excel文件转换为PDF。Excel文件由一个表格和一个图形填充。它们占用的空间比DIN A4页面大,因此当我使用以下代码时,我的Excel文件在PDF中被“分割”成几页。我想问一下,是否以及如何能够在一页上缩放PDF中的输出,或者忽略缩放,以便表格完全在一页上,而下面的图形则在一页上。也许将打印属性更改为仅一页会有所帮助。在Matlab中可以这样做吗

守则:

hExcel = actxserver('Excel.Application');
hWorkbook = hExcel.Workbooks.Open(sprintf('%s', 'C:\test.xls'));
hWorksheet = hWorkbook.Sheets.Item('Test');
hWorksheet.ExportAsFixedFormat('xlTypePDF', 'C:\test_out.pdf');
我在Microsoft帮助中查找了ExportAsFixedFormat,但我尝试更改的所有其他内容都无效,并且我收到错误消息。我试过了,例如:

hExcel = actxserver('Excel.Application');
hWorkbook = hExcel.Workbooks.Open(sprintf('%s', 'C:\test.xls'));
hWorksheet = hWorkbook.Sheets.Item('Test');
hWorksheet.ExportAsFixedFormat('xlTypePDF', 'C:\test_out.pdf', 'xlQualityStandard', true, true);`

提前谢谢。

试试下面我用宏录制的代码。 如果工作不正常,只需在保存为PDF之前录制您自己的pagesetup宏。

页面设置所有页面

Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
Application.PrintCommunication = False
With ActiveSheet.PageSetup
    .LeftHeader = ""
    .CenterHeader = ""
    .RightHeader = ""
    .LeftFooter = ""
    .CenterFooter = ""
    .RightFooter = ""
    .LeftMargin = Application.InchesToPoints(0.784313725490196)
    .RightMargin = Application.InchesToPoints(0.784313725490196)
    .TopMargin = Application.InchesToPoints(0.980392156862745)
    .BottomMargin = Application.InchesToPoints(0.980392156862745)
    .HeaderMargin = Application.InchesToPoints(0.509803921568628)
    .FooterMargin = Application.InchesToPoints(0.509803921568628)
    .PrintHeadings = False
    .PrintGridlines = False
    .PrintComments = xlPrintNoComments
    .PrintQuality = 600
    .CenterHorizontally = False
    .CenterVertically = False
    .Orientation = xlLandscape
    .Draft = False
    .PaperSize = xlPaperA4
    .FirstPageNumber = xlAutomatic
    .Order = xlDownThenOver
    .BlackAndWhite = False
    .Zoom = 100
    .PrintErrors = xlPrintErrorsDisplayed
    .OddAndEvenPagesHeaderFooter = False
    .DifferentFirstPageHeaderFooter = False
    .ScaleWithDocHeaderFooter = True
    .AlignMarginsHeaderFooter = False
    .EvenPage.LeftHeader.Text = ""
    .EvenPage.CenterHeader.Text = ""
    .EvenPage.RightHeader.Text = ""
    .EvenPage.LeftFooter.Text = ""
    .EvenPage.CenterFooter.Text = ""
    .EvenPage.RightFooter.Text = ""
    .FirstPage.LeftHeader.Text = ""
    .FirstPage.CenterHeader.Text = ""
    .FirstPage.RightHeader.Text = ""
    .FirstPage.LeftFooter.Text = ""
    .FirstPage.CenterFooter.Text = ""
    .FirstPage.RightFooter.Text = ""
End With
Application.PrintCommunication = True
Application.PrintCommunication = False
With ActiveSheet.PageSetup
    .LeftHeader = ""
    .CenterHeader = ""
    .RightHeader = ""
    .LeftFooter = ""
    .CenterFooter = ""
    .RightFooter = ""
    .LeftMargin = Application.InchesToPoints(0.25)
    .RightMargin = Application.InchesToPoints(0.25)
    .TopMargin = Application.InchesToPoints(0.75)
    .BottomMargin = Application.InchesToPoints(0.75)
    .HeaderMargin = Application.InchesToPoints(0.3)
    .FooterMargin = Application.InchesToPoints(0.3)
    .PrintHeadings = False
    .PrintGridlines = False
    .PrintComments = xlPrintNoComments
    .PrintQuality = 600
    .CenterHorizontally = False
    .CenterVertically = False
    .Orientation = xlLandscape
    .Draft = False
    .PaperSize = xlPaperA4
    .FirstPageNumber = xlAutomatic
    .Order = xlDownThenOver
    .BlackAndWhite = False
    .Zoom = 100
    .PrintErrors = xlPrintErrorsDisplayed
    .OddAndEvenPagesHeaderFooter = False
    .DifferentFirstPageHeaderFooter = False
    .ScaleWithDocHeaderFooter = True
    .AlignMarginsHeaderFooter = False
    .EvenPage.LeftHeader.Text = ""
    .EvenPage.CenterHeader.Text = ""
    .EvenPage.RightHeader.Text = ""
    .EvenPage.LeftFooter.Text = ""
    .EvenPage.CenterFooter.Text = ""
    .EvenPage.RightFooter.Text = ""
    .FirstPage.LeftHeader.Text = ""
    .FirstPage.CenterHeader.Text = ""
    .FirstPage.RightHeader.Text = ""
    .FirstPage.LeftFooter.Text = ""
    .FirstPage.CenterFooter.Text = ""
    .FirstPage.RightFooter.Text = ""
End With
Application.PrintCommunication = True
Application.PrintCommunication = False
With ActiveSheet.PageSetup
    .LeftHeader = ""
    .CenterHeader = ""
    .RightHeader = ""
    .LeftFooter = ""
    .CenterFooter = ""
    .RightFooter = ""
    .LeftMargin = Application.InchesToPoints(0.236220472440945)
    .RightMargin = Application.InchesToPoints(0.236220472440945)
    .TopMargin = Application.InchesToPoints(0.748031496062992)
    .BottomMargin = Application.InchesToPoints(0.748031496062992)
    .HeaderMargin = Application.InchesToPoints(0.31496062992126)
    .FooterMargin = Application.InchesToPoints(0.31496062992126)
    .PrintHeadings = False
    .PrintGridlines = False
    .PrintComments = xlPrintNoComments
    .PrintQuality = 600
    .CenterHorizontally = False
    .CenterVertically = False
    .Orientation = xlLandscape
    .Draft = False
    .PaperSize = xlPaperA4
    .FirstPageNumber = xlAutomatic
    .Order = xlDownThenOver
    .BlackAndWhite = False
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = 0
    .PrintErrors = xlPrintErrorsDisplayed
    .OddAndEvenPagesHeaderFooter = False
    .DifferentFirstPageHeaderFooter = False
    .ScaleWithDocHeaderFooter = True
    .AlignMarginsHeaderFooter = False
    .EvenPage.LeftHeader.Text = ""
    .EvenPage.CenterHeader.Text = ""
    .EvenPage.RightHeader.Text = ""
    .EvenPage.LeftFooter.Text = ""
    .EvenPage.CenterFooter.Text = ""
    .EvenPage.RightFooter.Text = ""
    .FirstPage.LeftHeader.Text = ""
    .FirstPage.CenterHeader.Text = ""
    .FirstPage.RightHeader.Text = ""
    .FirstPage.LeftFooter.Text = ""
    .FirstPage.CenterFooter.Text = ""
    .FirstPage.RightFooter.Text = ""
End With
Application.PrintCommunication = True
另存为PDF

ActiveWorkbook.ExportAsFixedFormat xlTypePDF, fName & ".pdf", _
 Quality:=xlQualityStandard, _
 IncludeDocProperties:=True, _
 IgnorePrintAreas:=False, _
 OpenAfterPublish:=False

谢谢你的回答,预定义的页面化妆与我的愿望很好。但我正在寻找一个在matlab中使用的代码,它可以自动执行这些步骤。也许我应该修改一下我的问题。我不是一个Matlab编码专家。对不起,我帮不上忙。