在domino开发中我们不可避免的要和报表打交道,一般就是生成各种Excel报表,本人主要为了自己在开发中方便,简单实现了一个基本类,现在功能有限,当然这个类我慢慢的根据以后遇到的需求逐渐完善。
Const EXCEL_APPLICATION = "Excel.application"
Private Const BASEERROR = 1200
'Private Const ERROR_NOSUCHCELL = BASEERROR + 0
'Private Const ERRORTEXT_NOSUCHCELL = "Excel Report - Could not get data from cell."
Const REG_97 = "Software\\Microsoft\\Office\\8.0\\Common\\InstallRoot" 'Registry Key Office 97
Const REG_2000 = "Software\\Microsoft\\Office\\9.0\\Common\\InstallRoot" 'Registry Key Office 2000
Const REG_XP = "Software\\Microsoft\\Office\\10.0\\Common\\InstallRoot" 'Registry Key Office XP
Const REG_2003 ="Software\\Microsoft\\Office\\11.0\\Common\\InstallRoot" 'Registry Key Office 2003
Const NAME_97 = "Office 97"
Const NAME_2000 = "Office 2000"
Const NAME_XP = "Office XP"
Const NAME_2003 = "Office 2003"
Class ExcelHelperClass ExcelHelper
Private xlApp As Variant ' Application object
Private strFilePath As String
Sub new()Sub new(xlFilename As String, isVisible As Boolean)
On Error Goto GeneralError
Set xlApp = CreateObject(EXCEL_APPLICATION) ' open the application
xlApp.Workbooks.Add xlFilename ' create an Excel workbook
xlApp.Visible = isVisible ' make it visible (or not)
strFilePath = xlFilename ' store the filename
Goto ExitSub
GeneralError:
If Not (xlApp Is Nothing) Then xlApp.quit ' quit, if there is an error
Resume ExitSub
ExitSub:
End Sub
Public Function save()Function save
xlApp.ActiveWorkbook.SaveAs( strFilePath )
End Function
Public Function saveAs()Function saveAs(newFilename)
xlApp.ActiveWorkbook.SaveAs( newFileName )
End Function
Public Function setCell()Function setCell( Sheet As Variant , row As Integer , column As Variant , value As Variant )
xlApp.Workbooks(1).Worksheets( Sheet ).Cells( row , column ).Value = value
End Function
Public Function getCell()Function getCell( Sheet As Variant , row As Integer , column As Variant ) As String
On Error Goto GeneralError
getCell = xlApp.Workbooks(1).Worksheets( Sheet ).Cells( row , column ).Value
Goto ExitSub
GeneralError:
getCell = ""
Resume ExitSub
ExitSub:
End Function
Public Function quit()Function quit
If Not (xlApp Is Nothing) Then
xlApp.Quit
Set xlApp = Nothing
End If
End Function
Public Function setVisibility()Function setVisibility(isVisible As Boolean)
If (isVisible And Not xlApp.Visible) Then xlApp.Visible = True
If (Not isVisible And xlApp.Visible) Then xlApp.Visible = False
End Function
Public Function setSheetName()Function setSheetName(Sheet As Variant,sheetName As String)
xlApp.Workbooks(1).Worksheets( Sheet ).Select
xlApp.Workbooks(1).Worksheets( Sheet ).Name=sheetName
End Function
Public Function setCellColor()Function setCellColor(Sheet As Variant, row As Integer, column As Variant, innercolor As Variant)
On Error Goto GeneralError
If Cstr(innercolor) <> "" Then
xlApp.Workbooks(1).Worksheets( Sheet ).Cells( row , column ).Interior.ColorIndex = innercolor
End If
Goto ExitSub
GeneralError:
Resume ExitSub
ExitSub:
End Function
Public Function setCellFont()Function setCellFont(Sheet As Variant, row As Integer, column As Variant, style As Variant, size As Variant, color As Variant)
On Error Goto GeneralError
If Cstr(style) <> "" Then
xlApp.Workbooks(1).Worksheets( Sheet ).Cells( row , column ).Font.FontStyle = style
End If
If Cstr(size) <> "" Then
xlApp.Workbooks(1).Worksheets( Sheet ).Cells( row , column ).Font.Size = size
End If
If Cstr(color) <> "" Then
xlApp.Workbooks(1).Worksheets( Sheet ).Cells( row , column ).Font.ColorIndex = color
End If
Goto ExitSub
GeneralError:
Resume ExitSub
ExitSub:
End Function
Public Function setRowFont()Function setRowFont(Sheet As Variant, row As Integer, style As Variant, size As Variant, color As Variant)
On Error Goto GeneralError
Dim rowpara As String
rowpara=Cstr(row)+":"+Cstr(row)
If Cstr(style) <> "" Then
xlApp.Workbooks(1).Worksheets( Sheet ).Rows(rowpara).Select
xlApp.Selection.Font.FontStyle = style
End If
If Cstr(size) <> "" Then
xlApp.Workbooks(1).Worksheets( Sheet ).Rows(rowpara).Select
xlApp.Selection.Font.Size = size
End If
If Cstr(color) <> "" Then
xlApp.Workbooks(1).Worksheets( Sheet ).Rows(rowpara).Select
xlApp.Selection.Font.ColorIndex = color
End If
Goto ExitSub
GeneralError:
Resume ExitSub
ExitSub:
End Function
Public Function getVersion()Function getVersion() As String
On Error Goto GeneralError
Dim formula As String
Dim SWVersion As String
Dim Versions List As String
Dim v As Variant
Versions(NAME_97) = REG_97
Versions(NAME_2000) = REG_2000
Versions(NAME_XP) = REG_XP
Versions(NAME_2003) = REG_2003
Forall vers In Versions
formula$ = | (@RegQueryValue("HKEY_LOCAL_MACHINE"; "| & vers & |";"Path")) |
v = Evaluate( formula$ )
If v(0) <> "" Then
getVersion = Listtag(vers)
Goto ExitSub
End If
End Forall
getVersion = ""
Goto ExitSub
GeneralError:
getVersion = ""
Resume ExitSub
ExitSub:
End Function
Public Function exportNotesView()Function exportNotesView(view As NotesView, Sheet As Variant, OffsetRow As Integer, OffsetCol As Integer, isWithheader As Boolean, includeIcons As Boolean, includeColors As Boolean, includeHidden As Boolean)
Dim viewnav As NotesViewNavigator
Dim entry As NotesViewEntry
Dim viewcolumns As Variant
Dim column As Integer
Dim row As Integer
Dim i As Integer
Dim array(0 To 9) As String
array(0)="A"
array(1)="B"
array(2)="C"
array(3)="D"
array(4)="E"
array(5)="F"
array(6)="G"
array(7)="H"
array(8)="I"
array(9)="J"
Set viewnav = view.CreateViewNav()
Set entry = viewnav.GetFirstDocument()
viewcolumns = view.Columns
row = OffsetRow + 1
column = OffsetCol + 1
If isWithHeader Then
Forall vc In viewcolumns
Call Me.setCell(Sheet, row, column, vc.title)
column = column + 1
End Forall
End If
While Not (entry Is Nothing)
row = row + 1
column = OffsetCol + 1
Forall cv In entry.ColumnValues
If doColumnExport(viewcolumns(column - OffsetCol - 1), includeHidden, IncludeIcons, includeColors) Then
Call Me.setCell(Sheet, row, column, Cstr(cv))
End If
column = column + 1
End Forall
Set entry = viewnav.GetNextDocument(entry)
Wend
For i=0 To (column-1)
Call Me.autoFit(Sheet,array(i))
Next
End Function
<img sr
Private Const BASEERROR = 1200
'Private Const ERROR_NOSUCHCELL = BASEERROR + 0
'Private Const ERRORTEXT_NOSUCHCELL = "Excel Report - Could not get data from cell."
Const REG_97 = "Software\\Microsoft\\Office\\8.0\\Common\\InstallRoot" 'Registry Key Office 97
Const REG_2000 = "Software\\Microsoft\\Office\\9.0\\Common\\InstallRoot" 'Registry Key Office 2000
Const REG_XP = "Software\\Microsoft\\Office\\10.0\\Common\\InstallRoot" 'Registry Key Office XP
Const REG_2003 ="Software\\Microsoft\\Office\\11.0\\Common\\InstallRoot" 'Registry Key Office 2003
Const NAME_97 = "Office 97"
Const NAME_2000 = "Office 2000"
Const NAME_XP = "Office XP"
Const NAME_2003 = "Office 2003"
Class ExcelHelperClass ExcelHelper
Private xlApp As Variant ' Application object
Private strFilePath As String
Sub new()Sub new(xlFilename As String, isVisible As Boolean)
On Error Goto GeneralError
Set xlApp = CreateObject(EXCEL_APPLICATION) ' open the application
xlApp.Workbooks.Add xlFilename ' create an Excel workbook
xlApp.Visible = isVisible ' make it visible (or not)
strFilePath = xlFilename ' store the filename
Goto ExitSub
GeneralError:
If Not (xlApp Is Nothing) Then xlApp.quit ' quit, if there is an error
Resume ExitSub
ExitSub:
End Sub
Public Function save()Function save
xlApp.ActiveWorkbook.SaveAs( strFilePath )
End Function
Public Function saveAs()Function saveAs(newFilename)
xlApp.ActiveWorkbook.SaveAs( newFileName )
End Function
Public Function setCell()Function setCell( Sheet As Variant , row As Integer , column As Variant , value As Variant )
xlApp.Workbooks(1).Worksheets( Sheet ).Cells( row , column ).Value = value
End Function
Public Function getCell()Function getCell( Sheet As Variant , row As Integer , column As Variant ) As String
On Error Goto GeneralError
getCell = xlApp.Workbooks(1).Worksheets( Sheet ).Cells( row , column ).Value
Goto ExitSub
GeneralError:
getCell = ""
Resume ExitSub
ExitSub:
End Function
Public Function quit()Function quit
If Not (xlApp Is Nothing) Then
xlApp.Quit
Set xlApp = Nothing
End If
End Function
Public Function setVisibility()Function setVisibility(isVisible As Boolean)
If (isVisible And Not xlApp.Visible) Then xlApp.Visible = True
If (Not isVisible And xlApp.Visible) Then xlApp.Visible = False
End Function
Public Function setSheetName()Function setSheetName(Sheet As Variant,sheetName As String)
xlApp.Workbooks(1).Worksheets( Sheet ).Select
xlApp.Workbooks(1).Worksheets( Sheet ).Name=sheetName
End Function
Public Function setCellColor()Function setCellColor(Sheet As Variant, row As Integer, column As Variant, innercolor As Variant)
On Error Goto GeneralError
If Cstr(innercolor) <> "" Then
xlApp.Workbooks(1).Worksheets( Sheet ).Cells( row , column ).Interior.ColorIndex = innercolor
End If
Goto ExitSub
GeneralError:
Resume ExitSub
ExitSub:
End Function
Public Function setCellFont()Function setCellFont(Sheet As Variant, row As Integer, column As Variant, style As Variant, size As Variant, color As Variant)
On Error Goto GeneralError
If Cstr(style) <> "" Then
xlApp.Workbooks(1).Worksheets( Sheet ).Cells( row , column ).Font.FontStyle = style
End If
If Cstr(size) <> "" Then
xlApp.Workbooks(1).Worksheets( Sheet ).Cells( row , column ).Font.Size = size
End If
If Cstr(color) <> "" Then
xlApp.Workbooks(1).Worksheets( Sheet ).Cells( row , column ).Font.ColorIndex = color
End If
Goto ExitSub
GeneralError:
Resume ExitSub
ExitSub:
End Function
Public Function setRowFont()Function setRowFont(Sheet As Variant, row As Integer, style As Variant, size As Variant, color As Variant)
On Error Goto GeneralError
Dim rowpara As String
rowpara=Cstr(row)+":"+Cstr(row)
If Cstr(style) <> "" Then
xlApp.Workbooks(1).Worksheets( Sheet ).Rows(rowpara).Select
xlApp.Selection.Font.FontStyle = style
End If
If Cstr(size) <> "" Then
xlApp.Workbooks(1).Worksheets( Sheet ).Rows(rowpara).Select
xlApp.Selection.Font.Size = size
End If
If Cstr(color) <> "" Then
xlApp.Workbooks(1).Worksheets( Sheet ).Rows(rowpara).Select
xlApp.Selection.Font.ColorIndex = color
End If
Goto ExitSub
GeneralError:
Resume ExitSub
ExitSub:
End Function
Public Function getVersion()Function getVersion() As String
On Error Goto GeneralError
Dim formula As String
Dim SWVersion As String
Dim Versions List As String
Dim v As Variant
Versions(NAME_97) = REG_97
Versions(NAME_2000) = REG_2000
Versions(NAME_XP) = REG_XP
Versions(NAME_2003) = REG_2003
Forall vers In Versions
formula$ = | (@RegQueryValue("HKEY_LOCAL_MACHINE"; "| & vers & |";"Path")) |
v = Evaluate( formula$ )
If v(0) <> "" Then
getVersion = Listtag(vers)
Goto ExitSub
End If
End Forall
getVersion = ""
Goto ExitSub
GeneralError:
getVersion = ""
Resume ExitSub
ExitSub:
End Function
Public Function exportNotesView()Function exportNotesView(view As NotesView, Sheet As Variant, OffsetRow As Integer, OffsetCol As Integer, isWithheader As Boolean, includeIcons As Boolean, includeColors As Boolean, includeHidden As Boolean)
Dim viewnav As NotesViewNavigator
Dim entry As NotesViewEntry
Dim viewcolumns As Variant
Dim column As Integer
Dim row As Integer
Dim i As Integer
Dim array(0 To 9) As String
array(0)="A"
array(1)="B"
array(2)="C"
array(3)="D"
array(4)="E"
array(5)="F"
array(6)="G"
array(7)="H"
array(8)="I"
array(9)="J"
Set viewnav = view.CreateViewNav()
Set entry = viewnav.GetFirstDocument()
viewcolumns = view.Columns
row = OffsetRow + 1
column = OffsetCol + 1
If isWithHeader Then
Forall vc In viewcolumns
Call Me.setCell(Sheet, row, column, vc.title)
column = column + 1
End Forall
End If
While Not (entry Is Nothing)
row = row + 1
column = OffsetCol + 1
Forall cv In entry.ColumnValues
If doColumnExport(viewcolumns(column - OffsetCol - 1), includeHidden, IncludeIcons, includeColors) Then
Call Me.setCell(Sheet, row, column, Cstr(cv))
End If
column = column + 1
End Forall
Set entry = viewnav.GetNextDocument(entry)
Wend
For i=0 To (column-1)
Call Me.autoFit(Sheet,array(i))
Next
End Function
<img sr
发表评论
-
Notes 和 Domino 已知限制
2008-01-13 10:11 860Notes 和 Domino 已知限制 功能测试 限制数据库的 ... -
TinyMCE与Domino集成
2008-02-03 12:27 838TinyMCE与Domino集成一:TinyMCE简介 Tin ... -
domino server端的Notes.ini详解
2008-02-19 08:46 1127Web代理监控与调式问题 Web代理在服务器的执行优先 ... -
Lotus开发之Lotus Notes中域的验证
2008-03-10 11:41 1360一:介绍 Lotus中的域主要有以下的类型:文本,日 ... -
以Ajax方式显示Lotus Notes视图的javasript类库----NotesView2
2008-03-28 20:52 762一:简介 NotesView2是一个使用javascript开 ... -
[转载]资深程序员点评当前某些对Lotus Domino 的不实评论
2008-04-09 13:30 1078实现机关办公自动化工作需要计算机技术的支持 ... -
Undokumentierte @Formeln/LotusScript im Lotus Notes Client/Server
2008-05-16 17:29 1266Erstellung von Replik-IDs mitt ... -
操作Domino数据库的设计元素
2008-05-27 15:46 1074在Domino的数据库中有数据文档和设计文档两种文档。设计文档 ... -
Lotus开发基本性能优化
2008-08-09 14:31 555一:一般的原则1. 视图 ... -
如何开发Domino中的WebService
2008-11-26 21:45 1276在domino中写webservice可以 ... -
Notes中几个处理多值域的通用函数
2008-12-29 14:21 7401.查找出查找内容在多值域中的索引值getItemIndex( ... -
关于Domino数据库的软删除
2009-02-03 20:40 974在Domino的数据库属性的 “高级” 附签(选择文件-> ... -
Lotus开发性能优化
2009-06-23 21:30 1074之前也总结过一篇关于 ...
相关推荐
在Lotus Domino应用程序中,有时需要将数据导出到更通用的格式,如Microsoft Excel,以便于数据分析或共享。在给定的代码片段中,展示了如何通过LotusScript实现从Lotus Domino数据库( Lotus Domino CS)导出选择的...
标题中的"Domino视图数据导出到Excel的代码"涉及到的是一个JavaScript脚本,用于将Domino应用中的视图数据导出到Microsoft Excel电子表格中。这种功能在数据分析、报表制作或者用户需要离线查看数据时非常有用。以下...
Domino notes java版导出excel,需要组件poi支持,解决Domino日常数据批量导出需求!
总之,通过Java代理和Apache POI,我们可以轻松地在Lotus Domino的BS开发中实现Excel文件的导出,提供给用户一个直观的数据导出功能。这个过程涉及到Java编程、Domino服务器的交互以及理解Excel文件的结构,对于提升...
lotus domino CS Excel导出.txt
### LotusScript代理导出数据到Excel 在处理企业级应用时,经常需要将数据库中的数据导出至Excel格式,以方便进行进一步的数据分析或报告制作。对于Lotus Notes/Domino平台,通常有两种方法实现这一功能:前端...
在这个"domino xpags 开发 Excel导入导出完整例子"中,我们将深入探讨如何利用XPAGS来实现Excel文件的导入与导出功能,这对于企业级应用中数据管理和分析至关重要。 首先,让我们关注"导出excel.doc"文件。这个文档...
这种Domino与Excel的交互方式在实际工作中非常有用,例如,当需要将大量数据从Excel报表导入到Domino数据库进行分析,或者定期从Domino数据库导出数据以生成自定义报告时。 通过上述介绍,我们可以看到,利用...
lotus Domino BS开发 lotusscript导出excel方法一
lotus Domino BS开发 lotusscript导出excel样式说明
如上文代码所示,`OutputToExcel` 类实现了将Lotus Domino视图的数据导出到Excel文件的过程。这个过程的核心在于设置正确的MIME类型,即`application/vnd.ms-excel`,这使得浏览器能够识别并打开生成的内容为Excel...
在Lotus Domino的Web应用程序(BS,Browser-Server)开发中,经常需要处理数据的导入导出功能。这里我们讨论的重点是如何使用LotusScript来动态导出数据到Excel文件。LotusScript是一种专为Lotus Domino设计的脚本...
收藏的dominoExcel导入、导出样例。
在这个特定的资源中,标题提到的是“使用Excel对象导出edb数据易语言源码”,这意味着我们将讨论如何利用易语言来操作数据库,并将数据导出到Microsoft Excel格式。 首先,我们要了解“edb”数据格式。EDB...
在日常工作中,我们经常会遇到将Notes中的数据导入或导出到Excel的需求。这种需求通常出现在数据统计、数据分析、报告生成等场景。通过LotusScript,我们可以很方便地实现Notes与Excel之间的数据交换。本文将详细...
LotusScript 代理导出Excel是Lotus Domino应用程序中一种常见的数据处理技术,它允许开发者通过编程方式将 Lotus Domino 数据库中的信息导出到Microsoft Excel文件中,以便于数据分析、报表制作或与其他系统进行数据...
在Domino中,提取的Excel数据可以被保存到Notes文档中,或者进一步整合到数据库的其他部分。这使得Domino能够与外部数据源交互,增强了其作为企业级协作平台的能力。 总结来说,"lotus/domino提取Excel文件内容例库...
在CS(Client-Side,客户端)开发中,从Excel导入数据到应用程序是一个常见的需求,尤其在数据处理和管理中。这段代码示例是用于Lotus Notes应用中的,它展示了如何利用VBA(Visual Basic for Applications)来实现...
在Lotus Domino开发中,XML(eXtensible Markup Language)是一种重要的数据交换格式,而DXL(Domino XML)是IBM Lotus Domino特有的XML表示,用于表单、视图、数据库设计等元素的导入和导出。从Domino 6.0开始,...
Domino数据库浏览器是一个小工具,可以用来浏览Lotus Domino数据库文件中(或独立的NSF文件中)的所有文档数据,并将其导出。本软件非常适合于需要将老DOMINO上的信息和数据转移到新系统中的企业。借助于本工具,...