excel生成表内部函数可以生成文件,放入HttpRequest事件中想实现网页显示excel 提示无法将类型为“System.String”的对象强制转换为类型“Foxtable.XLS.Book”。
以下内容是专门发给有点蓝浏览
excel内部函数代码如下:【经测试可以正常生成表及数据】
Dim tbn As String = args(0) 'uuid传参
Dim Book As New XLS.Book(ProjectPath & "Attachments\财产收入情况申报表.xlsx")
Dim fl As String = ProjectPath & "Reports\财产收入情况申报表.xlsx"
book.AddDataTable("填报人信息","测试","Sele ct * from {填报人信息} where uuid= '" & tbn & "'") '添加父表
book.AddDataTable("亲属信息","测试","Sele ct * from {亲属信息} where uuid= '" & tbn & "'") '添加子表
book.AddDataTable("收入情况","测试","Sel ect * from {收入情况} where uuid= '" & tbn & "'") '添加子表
book.AddDataTable("存款情况","测试","Sel ect * from {存款情况} where uuid= '" & tbn & "'") '添加子表
book.AddDataTable("其他投资","测试","Sele ct * from {其他投资} where uuid= '" & tbn & "'") '添加子表
book.AddDataTable("债务情况","测试","Sele ct * from {债务情况} where uuid= '" & tbn & "'") '添加子表
book.AddDataTable("私人借款","测试","Sele ct * from {私人借款} where uuid= '" & tbn & "'") '添加子表
book.AddDataTable("债权情况","测试","Sel ect * from {债权情况} where uuid= '" & tbn & "'") '添加子表
book.AddDataTable("其他说明","测试","Sele ct * from {其他说明} where uuid= '" & tbn & "'") '添加子表
book.AddDataTable("经商办企业情况","测试","Sele ct * from {经商办企业情况} where uuid= '" & tbn & "'") '添加子表
book.AddDataTable("车辆情况","测试","Sele ct * from {车辆情况} where uuid= '" & tbn & "'") '添加子表
book.AddDataTable("房产情况","测试","Sele ct * from {房产情况} where uuid= '" & tbn & "'") '添加子表
book.AddDataTable("投资情况","测试","Se lect * from {投资情况} where uuid= '" & tbn & "'") '添加子表
book.AddDataTable("持有基金情况","测试","Sel ect * from {持有基金情况} where uuid= '" & tbn & "'") '添加子表
book.AddDataTable("持有期货","测试","Sele ct * from {持有期货} where uuid= '" & tbn & "'") '添加子表
book.AddDataTable("持有其他投资","测试","Sel ect * from {持有其他投资} where uuid= '" & tbn & "'") '添加子表
book.AddDataTable("投资公司企业情况","测试","Sel ect * from {投资公司企业情况} where uuid= '" & tbn & "'") '添加子表
book.AddDataTable("其他财产申报","测试","Sele ct * from {其他财产申报} where uuid= '" & tbn & "'") '添加子表
book.AddRelation("填报人信息","uuid","亲属信息","uuid") '建立关联
book.AddRelation("填报人信息","uuid","收入情况","uuid") '建立关联
book.AddRelation("填报人信息","uuid","存款情况","uuid") '建立关联
book.AddRelation("填报人信息","uuid","其他投资","uuid") '建立关联
book.AddRelation("填报人信息","uuid","债务情况","uuid") '建立关联
book.AddRelation("填报人信息","uuid","私人借款","uuid") '建立关联
book.AddRelation("填报人信息","uuid","债权情况","uuid") '建立关联
book.AddRelation("填报人信息","uuid","其他说明","uuid") '建立关联
book.AddRelation("填报人信息","uuid","经商办企业情况","uuid") '建立关联
book.AddRelation("填报人信息","uuid","车辆情况","uuid") '建立关联
book.AddRelation("填报人信息","uuid","房产情况","uuid") '建立关联
book.AddRelation("填报人信息","uuid","投资情况","uuid") '建立关联
book.AddRelation("填报人信息","uuid","持有基金情况","uuid") '建立关联
book.AddRelation("填报人信息","uuid","持有期货","uuid") '建立关联
book.AddRelation("填报人信息","uuid","持有其他投资","uuid")
book.AddRelation("填报人信息","uuid","投资公司企业情况","uuid") '建立关联
book.AddRelation("填报人信息","uuid","其他财产申报","uuid") '建立关联
Book.Build() '生成细节区
Book.Save(fl) '保存工作簿
'Dim Proc As New Process '打开工作簿
'Proc.File = fl
'Proc.Start()
vars("fl")=fl
在命令窗口中运行 Functions.Execute("excel","f9a4cb7f-2ea2-41aa-99c4-3d95bb7d04dd") 能够正常生成表及数据
HttpRequest事件中代码如下:
If e.Path.StartsWith("Reports\")
e.Resp
Select Case e.Path
Case "Reports\ckd.htm"
Functions.Execute("excel","f9a4cb7f-2ea2-41aa-99c4-3d95bb7d04dd")
MessageBox.Show(vars("fl"))
e.WriteBookAsHTML(vars("fl"))
Case "Reports\jianli.htm"
Dim Book As New XLS.Book(ProjectPath & "Attachments\财产收入情况申报表.xlsx")
e.WriteBookAsHTML(Book)
Case Else
e.AsReportServer("Reports\")
End Select
End If
运行提示:
.NET Framework 版本:4.0.30319.42000
Foxtable 版本:2022.1.30.2
错误所在事件:项目,HttpRequest
详细错误信息:
无法将类型为“System.String”的对象强制转换为类型“Foxtable.XLS.Book”。
此主题相关图片如下:11.png
此主题相关图片如下:22.png
[此贴子已经被作者于2022/4/21 19:46:40编辑过]