Use of owc (Office Web component)

Source: Internet
Author: User

Owc (Office Web component) is a self-contained Web Report Component tool in Microsoft Office. Although this tool is far inferior to crystal report, it has no lisence problem, as long as the company has purchased the office, it can use this report tool for free. Therefore, many companies use owc to implement the report function. Unfortunately, this tool does not have any graphical operation interface, it only provides some automated calling interfaces. The following is a general class for calling owc to generate reports in my work. I will share with you here.

'General owc class

Imports owc 'owc9. 0 (Office2000)
Imports system. Io

Public class owc

Public sub new ()

End sub

Public Function getowcstr (byval dT as datatable, byval columnname as string) as string
Use/T as the delimiter for 'owc11, and controlchars. tab as the delimiter for 'owc11 '.
Dim strreturn as string = ""

For I as integer = 0 to DT. Rows. Count-1
Strreturn = strreturn + dt. Rows (I) (columnname). tostring () + controlchars. Tab
Next

If strreturn. indexof (controlchars. Tab)> = 0 then
Strreturn = strreturn. substring (0, strreturn. lastindexof (controlchars. Tab ))
End if

Return strreturn
End Function

Public Function evaluate (byval strpath as string, byval chartcategoriesstr as string, byval chartvalues1str as string, byval escape as string, byval titlecaption as string, byval axesytitle as string, byval axesxtitle as string, byval series1caption as string, byval series2caption as string) as string
Removefile (strpath)

Dim ochartspace as chartspaceclass = new chartspaceclass

Ochartspace. charts. Add (0)
Ochartspace. Border. color = "white"
Ochartspace. Charts (0). type = chartcharttypeenum. chcharttypecolumnclustered

'Heading
Ochartspace. Charts (0). hastitle = true
Ochartspace. Charts (0). Title. Font. Name = ""
Ochartspace. Charts (0). Title. Font. size = 14
Ochartspace. Charts (0). Title. Caption = titlecaption'

'Add data series 1
Ochartspace. Charts (0). seriescollection. Add (0)
Ochartspace. Charts (0). seriescollection (0). datalabelscollection. Add ()
'Display value
Ochartspace. Charts (0). seriescollection (0). datalabelscollection (0). haspercentage = false
Ochartspace. Charts (0). seriescollection (0). datalabelscollection (0). hasvalue = true
'Font
Ochartspace. Charts (0). seriescollection (0). datalabelscollection (0). Font. Name = "verdana"
Ochartspace. Charts (0). seriescollection (0). datalabelscollection (0). Font. size = 10
Ochartspace. Charts (0). seriescollection (0). datalabelscollection (0). Font. Bold = true
Ochartspace. Charts (0). seriescollection (0). datalabelscollection (0). Font. color = "white"
Ochartspace. Charts (0). seriescollection (0). datalabelscollection (0). Position = chartdatalabelpositionenum. chlabelpositioncenter
'Data Source
Ochartspace. Charts (0). seriescollection (0). setdata (chartdimensionsenum. chdimcategories, convert. toint32 (chartspecialperformancesenum. chdataliteral), chartcategoriesstr)
Ochartspace. Charts (0). seriescollection (0). setdata (chartdimensionsenum. chdimvalues, convert. toint32 (chartspecialperformancesenum. chdataliteral), chartvalues1str)

'Add data generation 2
Ochartspace. Charts (0). seriescollection. Add (1)
Ochartspace. Charts (0). seriescollection (1). datalabelscollection. Add ()
'Display value
Ochartspace. Charts (0). seriescollection (1). datalabelscollection (0). haspercentage = false
Ochartspace. Charts (0). seriescollection (1). datalabelscollection (0). hasvalue = true
'Font
Ochartspace. Charts (0). seriescollection (1). datalabelscollection (0). Font. Name = "verdana"
Ochartspace. Charts (0). seriescollection (1). datalabelscollection (0). Font. size = 10
Ochartspace. Charts (0). seriescollection (1). datalabelscollection (0). Font. Bold = true
Ochartspace. Charts (0). seriescollection (1). datalabelscollection (0). Font. color = "white"
Ochartspace. Charts (0). seriescollection (1). datalabelscollection (0). Position = chartdatalabelpositionenum. chlabelpositioncenter
'Data Source
Ochartspace. Charts (0). seriescollection (1). setdata (chartdimensionsenum. chdimcategories, convert. toint32 (chartspecialperformancesenum. chdataliteral), chartcategoriesstr)
Ochartspace. Charts (0). seriescollection (1). setdata (chartdimensionsenum. chdimvalues, convert. toint32 (chartspecialperformancesenum. chdataliteral), chartvalues2str)

'Coordinate axis: horizontal axis
Ochartspace. Charts (0). axes (0). hastitle = true
Ochartspace. Charts (0). axes (0). Title. Font. Name = ""
Ochartspace. Charts (0). axes (0). Title. Font. size = 10
Ochartspace. Charts (0). axes (0). Title. Caption = axesxtitle'

'Coordinate axis: vertical axis
Ochartspace. Charts (0). axes (1). hastitle = true
Ochartspace. Charts (0). axes (1). Title. Font. Name = ""
Ochartspace. Charts (0). axes (1). Title. Font. size = 10
Ochartspace. Charts (0). axes (1). Title. Caption = axesytitle'

'Legend
Ochartspace. haschartspacelegend = true
Ochartspace. chartspacelegend. Font. Name = ""
Ochartspace. chartspacelegend. Font. size = 9
Ochartspace. chartspacelegend. Position = chartlegendpositionenum. chlegendpositionbottom
'Legend prompt
Ochartspace. Charts (0). seriescollection (0). Caption = "=" + series1caption
Ochartspace. Charts (0). seriescollection (1). Caption = "=" + series2caption

Dim picturename as string = guid. newguid (). tostring () + ". GIF"
Ochartspace. exportpicture (strpath + picturename, "GIF", 730,320)

Return "../images/temp/" + picturename
End Function

Private sub removefile (byval strpath as string)
Dim di as directoryinfo = new directoryinfo (strpath)
Dim FS as fileinfo () = Di. getfiles ()
Dim Fi as fileinfo
For each fi in FCM
If fi. extension. tostring () = ". GIF" then
If datediff (dateinterval. Day, Fi. creationtime, datetime. Now. Date)> 0 then
Fi. Delete ()
End if
End if
Next
End sub

End Class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.