Call the Excel2000 within the VB component to implement GIF pie chart
http://www.tongyi.net Click: 405
Calling Excel2000 within the VB component to implement GIF pie chart When I first use Excel, it is powerful for Excel's chart function, and the pictures are also very beautiful. Later I tried to call the VBA function supported by Excel in VB, and found that the function is indeed very cumbersome. Later, consider using VB to cover a layer of Excel, write objects, remove the features we don't need. This is more convenient so that it is more convenient. Here, I will introduce a pie chart component written in VB, you only need to give it a few simple parameters, you can generate a picture of a GIF format for you. The example is as follows: DIM obj set obj = creteObject ("Chinaaspchart.pie") Obj.addValue "Men", 150 Obj.AddValue "Female", 45 Obj.AddValue "Don't know", 15 obj.ChartName = "Gender scale map "Obj.FileName =" d: /123.gif "Obj.saveChart In addition to being called in VB, this code can also be called in ASP. Let's write our components below. 1.New Project, select ActiveX DLL, select Project1 on the Project Explorer panel, and then modify its Name on the property panel to ChinaPchart. Also modified the Class modules inside to PIE 2. Save the project, save the Project to ChinaAaspchart.vbp, save the class1.cls as a PIE.CLS. 3. Menu Project, select menu item References, then select Microsoft Active Server Pages OjBect Library, Microsoft Excel 9.0 Object Library, COM Services Type Library.
Note: No COM Service Type Library on NT4 / Win98, you should choose Microsoft Transaction Server Type Library 4. Edit Pie.cls, code as follows: '-------------------------------------------------------------------------------------------------- -------------------------------------------------- ------------- Dim xl Dim m_chartName Dim m_chartData () Dim m_chartType Dim m_fileName Public ErrMsg Public foundErr Dim iCount Type m_Value label As String value As Double End Type Dim tValue As m_Value Public Property Let ChartType ( ChartType) m_chartType = ChartType End Property Public Property Get ChartType () ChartType = m_chartType End Property Public Property Let chartName (chartName) m_chartName = chartName End Property Public Property Get chartName () chartName = m_chartName End Property Public Property Let FileName (fname) m_fileName = FNAME End Property Public Property Get FileName () FileName = M_FileName End Property Public Sub AddValue (Label, Value) iCount = ICOUNT 1 Redim Preserve M_ChartData (iCount) TValue.label = LA bel tValue.value = value m_chartData (iCount) = tValue End Sub Public Sub SaveChart () On Error Resume Next Dim iSheet Dim i Set xl = New Excel.Application xl.Application.Workbooks.Add xl.Workbooks (1) .Worksheets ( "sheet1"). Activate if err.number <> 0 dam = true errmsg = err.description Err.Clear else xl.workbooks (1) .Worksheets ("sheet1"). Cells ("2, 1"). Value = M_ChartName for i = 1 to iCount XL.Worksheets ("sheet1"). Cells (1, i 1) .value = m_chartdata (i) .Label XL.Worksheets ("
Sheet1 "). Cells (2, i 1) .value = m_chartdata (i) .value next xl.charts.add xl.activechart.charttype = m_charttype xl.activechart.setSourceData XL.Sheets (" sheet1 "). Range "A1:" & chr ((iCount MOD 26) ASC ("a")) & "2"), 1 xl.activechart.Location 2, "Sheet1" with xl.activechart .haastitle = true .charttitle.characters. Text = m_chartName End With xl.ActiveChart.ApplyDataLabels 2, False, _ True, False With xl.Selection.Border .Weight = 2 .LineStyle = 0 End With xl.ActiveChart.PlotArea.Select With xl.Selection.Border .Weight = Xlhairline .LinesTyle = xlnone end with xl.selection.interior.colorindex = xlnone xl.activeWindow.visible = false xl.displayalerts = false xl.activechart.export m_filename, Filtername: = "gif" xl.Workbooks.Close If Err.Number <> 0 Then foundErr = True ErrMsg = ErrMsg Err.Clear End If End If Set xl = Nothing End Sub Private Sub Class_Initialize () iCount = 0 foundErr = False ErrMsg = "" m_chartType = - 4102 'XL3DPIE '54' Columnar Diagram End Sub '--------------------------------------- -------------------------------------- 5. If you implement the column map? In fact, the previous code has implemented the function of the histogram, just the default is the pie chart function.