我认为您在使用 activex 的安全障碍方面遇到的问题是因为您将 excel 嵌入到网页中。应该可以通过使用 Excel 的发布方法将工作表发布为 HTML 来打印工作表。我用它来为电子邮件创建 HTML。
Dim rngeTableRange As Range
Dim lsTableFileName As String
lsTableFileName = <filepath and name for HTML output as string>
Set rngeTableRange = ActiveSheet.UsedRange
ActiveWorkbook.PublishObjects.Add(xlSourceRange, lsTableFileName, _
rngeTableRange.Parent.Name, rngeTableRange.Address, xlHtmlStatic).Publish True
如果您希望打印输出显示为电子表格,您可以在发布工作表之前添加边框。以下 VBA 代码将在每个单元格周围放置一个边框:
With ActiveSheet.UsedRange.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With ActiveSheet.UsedRange.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With ActiveSheet.UsedRange.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With ActiveSheet.UsedRange.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With ActiveSheet.UsedRange.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With ActiveSheet.UsedRange.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
End With
结果应该是不会导致安全警告的电子表格的 HTML 图像,我认为它是可打印的。