excel - 如何将 Access 报表(包括子报表)保存为 Excel 兼容文件和可读 PDF?
问题描述
我定义了一个 Access (Office 365) 报告。当我在我设计的 Access 应用程序中打开它时,它会正确打开并显示正常。该应用程序与处理医疗保健数据有关,因此我们希望通过将报告另存为 PDF(第一个偏好)或 Excel 文件(第二个偏好)来保存报告中的信息日志。代码创建文件,但两个文件中都没有可用的内容。当我尝试打开 excel 文件时,我收到错误“无法打开文件,因为文件格式扩展名无效。”。当我打开 PDF 文件时,它包含错误信息。
我在表单上有一个按钮。这是事件过程。
Private Sub cmdRpt_Excel_Proc_Summary_Click()
Call ExportReport("Rpt_FileProcessing_Summary", "Rpt_FileProc_Summary", acFormatXLS)
Call ExportReport("Rpt_FileProcessing_Summary", "Rpt_FileProc_Summary", acFormatPDF)
End Sub
这是 ExportReport 的代码
Sub ExportReport(strQry As String, strOutFile As String, strOutType As String)
On Error GoTo errHandler
Dim xlApp As Object, wkbk As Object
Dim strMsg
Dim strFileNm As String
strFileNm = DEFAULT_FOLDER & strOutFile & "_" & Format(Now(), "yyyy-mm-dd_hhnn")
If strOutType = acFormatXLS Then
strFileNm = strFileNm & ".xlsx"
Else
strFileNm = strFileNm & ".pdf"
End If
'DoCmd.OutputTo acOutputReport, strQry, strOutType, strFileNm, , , , acExportQualityScreen
DoCmd.OutputTo acOutputReport, strQry, strOutType, strFileNm, True
If strOutType = acFormatXLS Then
Set xlApp = CreateObject("Excel.Application")
With xlApp
.Visible = True
Set wkbk = .Workbooks.Open(strFileNm)
End With
End If
procDone:
Set wkbk = Nothing
Set xlApp = Nothing
Exit Sub
errHandler:
strMsg = Err.Description
MsgBox strMsg, vbExclamation, "Unanticipated Error"
Resume procDone
End Sub
错误事件永远不会触发。创建了 excel 和 pdf 文件,但是我无法打开 excel 文件,并且 pdf 文件的内容是:
任何诊断问题的帮助将不胜感激。提前谢谢
解决方案
尝试使用其他程序来读取这些文件,因为 MS Edge 有时有点奇怪。您可以使用 FireFox 阅读 .pdf
你能打开Excel文件吗?
推荐阅读
- sql - SQLite - 如何计算不包括具有特定列相同值的行的行
- c++ - 覆盖另一个方法使用的超类回调函数 [C++]
- java - 如何在列表中获取列表的困难
- python - 我正在尝试提出一个问题并让系统存储该问题的答案并用 Python 打印出来
- python - 如何将文件从一个目录移动到另一个目录?
- angular - Angular 直接链接到页面重定向到主页
- c# - VS 2019 项目文件夹中的 sass/less 文件不可见
- swift - 在swift IOS中获取FaceId的授权状态
- php - PHP - 如何在文件之间共享 JSON 数据
- c++ - Is it possible to insert escape sequence in a raw string literal?