domino生成Excel图表
現(xiàn)在創(chuàng)建一個(gè)視圖操作名為 Generate Chart1,功能是統(tǒng)計(jì)各個(gè)年齡段(20 以下,20~29,30~39,40~49,50~59,60 及以上)的人數(shù)的百分比并以 Chart1.xls 為模板生成 Excel 餅圖,如果想生成不同的圖表,只需要將模板中的圖表格式類型改變并保存即可。代碼如下:
Sub Click(Source As Button)
????'定義一個(gè)數(shù)組來(lái)保存各個(gè)年齡段的人數(shù)
????Dim countArr(5) As Integer
????Dim s As New NotesSession
????Dim ws As New NotesUIWorkspace
????Dim db As NotesDatabase
????Set db = s.CurrentDatabase
????Dim vw As NotesView
????Set vw = db.GetView("ExcelTest")
????Dim doc As NotesDocument
????Set doc = vw.GetFirstDocument
????'計(jì)算各個(gè)年齡段人數(shù)
????While Not doc Is Nothing
????????age% = Cint(doc.Age(0))
????????If age%<20 Then
????????????countArr(0) = countArr(0) + 1
????????Elseif age%>=20 And age%<30 Then
????????????countArr(1) = countArr(1) + 1
????????Elseif age%>=30 And age%<40 Then
????????????countArr(2) = countArr(2) + 1
????????Elseif age%>=40 And age%<50 Then
????????????countArr(3) = countArr(3) + 1
????????Elseif age%>=50 And age%<60 Then
????????????countArr(4) = countArr(4) + 1
????????Else ???????????
????????????countArr(5) = countArr(5) + 1
????????End If
????????Set doc = vw.GetNextDocument(doc)
????Wend
????'生成Excel圖表
????Call generateExcelChart1(countArr, "C:\Chart1.xls")
????
????Dim uiChartDoc As NotesUIDocument
????Set uiChartDoc = ws.ComposeDocument( "", "", "Chart" )
????uiChartDoc.GotoField("Body")
????'將生成的Excel圖表粘貼到一個(gè)文檔中
????Call uiChartDoc.Paste
End Sub
?
其中生成 Excel 圖表的過(guò)程 generateExcelChart1() 代碼如下:
Sub generateExcelChart1(countArr As Variant, excelFileName As String)
????'定義Excel相關(guān)變量
????Dim excelApplication As Variant
????Dim excelWorkbook As Variant
????Dim excelSheet As Variant
????'創(chuàng)建Excel對(duì)象
????Set excelApplication = CreateObject("Excel.Application") ???
????'將Excel程序設(shè)置為不可見(jiàn)
????excelApplication.Visible = False
????'打開(kāi)模版文件
????Set excelWorkbook = excelApplication.Workbooks.Open(excelFileName)
????Set excelSheet = excelWorkbook.Worksheets("Sheet1")
????'為圖表填充源數(shù)據(jù)
????excelSheet.Cells(2,2) = countArr(0)
????excelSheet.Cells(2,3) = countArr(1)
????excelSheet.Cells(2,4) = countArr(2)
????excelSheet.Cells(2,5) = countArr(3)
????excelSheet.Cells(2,6) = countArr(4)
????excelSheet.Cells(2,7) = countArr(5)
????'將生成的圖表復(fù)制到剪貼板
????excelSheet.ChartObjects(1).Chart.ChartArea.Copy
????'不保存退出Excel應(yīng)用程序
????excelWorkbook.Close False
????excelApplication.Quit
End Sub
??
?
?
?
總結(jié)
以上是生活随笔為你收集整理的domino生成Excel图表的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 第4章 Python 数字图像处理(DI
- 下一篇: xdoj机器人ac