一般来说,在一些大型OA中最常用,而且也比较难的部分莫过于一些报表生成,压缩,下载等操作了,下面我就将一些示例代码总结一下:
通过Excel模板生成Excel报表代码:
首先进行如下操作,以确保网络用户拥有创建报表的权限:Microsoft Excel 应用程序-》右键属性-》安全-》全部改为自定义加入.NET用户权限。
Dim mClsExcel As New Reportforms.DataAccess.clsExcel
Dim mFromPathFile As String
Dim mToPathFile As String
mFromPathFile = Server.MapPath("1.xls")
mToPathFile = "2.xls"
If File.Exists(mToPathFile) = True Then
File.Delete(mToPathFile)
End If
File.Copy(mFromPathFile, mToPathFile)
File.SetAttributes(mToPathFile, FileAttributes.Archive)
Dim ds As DataSet = New DataSet
mClsExcel.OpenFile(mToPathFile )
Try
ds = GetDate()
mClsExcel.SelectSheet(1)
mClsExcel.SetExcelCellValue("A", "1", "单位数量")
mClsExcel.SetExcelCellValue("A", "2", "资料年份:" & SBDate)
mClsExcel.SetExcelCellValue("A", "3", "填报单位:" & UnitName & "(" & UnitCode & ")")
If mClsExcel.Addcenter(ds, "10", "C", 1) = True Then
End If
ds.Dispose()
ds = Nothing
Catch ex As Exception
End Try
mClsExcel.CloseFile()
压缩报表代码:
Shell(Server.MapPath("rar.exe") & " a -ep " & "1.rar" & " " & "", AppWinStyle.Hide, True)
报表下载代码:
System.Web.HttpContext.Current.Response.Redirect("1.rar")