我正在从另一个应用程序(DPlot Jr)复制到剪贴板生成的增强元文件,并将其粘贴到Excel(2007)工作表。从那里,我使用vba将该文件转换为pdf。这是我要做的代码:
' copy the graph eml file to the clip board
ret = DPlot_Command(doc, "[CopyPicture()]")
' copy the clip board contents to a new temp worksheet (under the covers)
'Hide the application
Application.ScreenUpdating = False
'Create a new temp worksheet
Set ws = ActiveWorkbook.Sheets.Add(After:=Sheets(1))
ws.Name = "Temp_Graph_DPJR"
ws.Activate
'Paste to the temp worksheet
ActiveSheet.Paste
'Save as pdf from excel
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
filename:=pdf_filename, _
OpenAfterPublish:=False
我发现,在PDF中创建的图像比图形的实际尺寸稍大。例如,图形的宽度应该是2.65英寸。PDF中图表的大小是2.816,所以大约0.166英寸或1 Pica,似乎被添加了。
虽然我可以,而且可能不得不,只是减少图像的大小最初的0.166",这似乎有点黑客,我只是想有图像的原始大小过来。
我发现,如果我将图像粘贴到图表表,大小保持不变,但图像在图表表页面上变成位图。
当我创建pdf时,我有所有正确的设置。我没有边距,实际大小等
还有人看到这个吗?有人能帮忙吗?我需要有一个pdf格式的图像。
谢谢你的帮助!
Russ
嗯,这很奇怪,不应该有什么不同,但它确实,到目前为止似乎是有效的。
在上面的工作流程中,在将EMF粘贴到工作表后,如果我选择该图像,然后将其复制到新的图表表,则保持原始大小,以及图形的矢量性质。下面是代码:
ret = DPlot_Command(doc, "[CopyPicture()]")
' copy the clip board contents to a new temp worksheet (under the covers)
'Hide the application
Application.ScreenUpdating = False
'Create a new temp worksheet
Set ws = ActiveWorkbook.Sheets.Add(After:=Sheets(1))
ws.Name = "Temp_Graph_DPJR"
ws.Activate
'Paste to the temp worksheet then select/copy that one
ActiveSheet.Paste
Selection.Copy
'Create a new temp chart
Set temp_chart = ActiveWorkbook.Charts.Add
'temp_chart.Name = "Temp_Chart"
'Set the linesytle of the border to none
temp_chart.ChartArea.Border.LineStyle = xlNone
'Paste the dplotjr graph to the chart sheet
'We had to do this as this maintained the size of the graph
'Dumb MS Excel worksheet
temp_chart.Paste
'Paste to the temp worksheet
'ActiveSheet.Paste
'Save as pdf from excel
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
filename:=pdf_filename, _
OpenAfterPublish:=False
这几乎就像Excel确定粘贴来自另一个应用程序并将位图粘贴到图表表,但如果它确定它来自自己,则将其粘贴为矢量图像。这可能是一个漏洞,将来可能会消失,但到目前为止似乎是有效的。
就其价值而言!