vb窗口使用excel文档格式.docx
《vb窗口使用excel文档格式.docx》由会员分享,可在线阅读,更多相关《vb窗口使用excel文档格式.docx(47页珍藏版)》请在冰豆网上搜索。
D3"
).Merge
).Value
合并效果"
格式设置
).Font.Name
黑体"
).Font.Size
15
).Borders(xlEdgeTop).Color
vbRed
).Borders(xlEdgeBottom).Color
).Borders(xlEdgeLeft).Color
).Borders(xlEdgeRight).Color
不提示直接保存为本地文件
Spreadsheet1.Export
c:
\xxx.xls"
ssExportActionNone
直接在Excel中打开
ssExportActionOpenInExcel
End
Sub
运行出来就是这个样子
因为整个编程中使用了VBA语法,所以还是很容易理解的
如果你的机器上安装了Office2000/xp/2003
那么你的机器上已经有使用文档及开发文档了,很详尽,参照一下,应该没啥问题。
我的机器装的是2003,在如下位置上有相关文档
C:
\Program
Files\Common
Files\Microsoft
Shared\Web
Components\10\2052
Components\11\2052
前面的文档都是使用帮助
OWCVBA11.CHM是开发文档
ChartSpace对象:
图形容器对象,也是顶层对象。
如果要使用OWC绘制图形,至少要创建一个ChartSpace对象。
所谓容器,就是说ChartSpace对象中可以包含多个图形对象,最多16个。
ChChart对象、ChCharts集合、ChCharts.Add()方法:
ChChart是图形对象。
一个柱状图、饼状图、散点图等都是一个图形对象,多个图形对象构成ChCharts集合。
ChartSpace对象就包含一个ChCharts集合,这些ChChart之间互相叠加,比如簇状条形图就是多个单柱状图的叠加,圆环套圆环图就是两个单圆环图的叠加。
通过ChCharts.Add()方法增加一个图形。
ChSeries对象、ChSeriesCollection集合、ChSeriesCollection.Add()方法:
帮助中说:
一个ChSeries对象表示图中的一个系列。
实际上,你可以这样理解,当图形容器中包含多个图形时,一个ChSeries对象就表示其中的一个图形,可以通过ChSeriesCollection集合,可以使用数组的方式访问各个ChSeries,比如ChSeriesCollection[0]表示第一个图形。
使用ChSeriesCollection.Add()方法在当前容器中新增一个图形。
Point属性和Points集合:
一个Point代表图形中的一个部分,比如柱状图的一条柱,饼状图的一个扇区等。
ChChart对象提供Points集合,可以使用数组的形式访问各个Point,比如Points[0]表示第1个部分。
Interior属性:
代表一个形状的内部空间。
比如,ChartSpace对象的Interior属性代表图形容器内、图形外的空间,一个扇区Interior属性表示该扇区的内部空间。
该属性在设置图形各个部分的颜色时起到重要作用。
窃以为,以上对象和属性的理解、使用非常关键,顺着它们找下去,标题、图例、数据标签、字体等重要的特性都能顺利找到。
OWC简介及其属性(转)
2008-10-2117:
06
Figure3OfficeWebComponents(version10)
组件
描述
PivotTable
使用户连接到支持OLEDBProviderforOLAPServices8.0或更高版的OLAP数据源上(也可连接到Excel电子数据表单和SQLServer、Access关系数据库)。
PivotTable控件允许用户对数据进行透视、分组、筛选和排序等操作。
Spreadsheet
提供电子数据表单用户接口,包括重算引擎和扩展函数库。
Chart
图形化显示来自某个绑定数据源、PivotTable或Spreadsheet控件的数据。
当Chart组件被绑定到PivotTable控件且用户重新透视数据时能自动刷新。
DataSource
管理与后台数据库服务器的通讯。
PivotTable和Spreadsheet组件实际上能单独连接到数据源,,不一定非得要DataSource组件。
这是因为其XML数据可以直接包含OLEDB连接串。
Figure4PivotTableandChart-relatedObjects
成员
PivotView
表示PivotTable的一个特定视图.用于对PivotTable视图中的行、列、标尺、格式化进行设置。
PivotDataAxis
包含与数据轴相关的方法和属性
PivotResultColumnAxis
包含与列轴相关的方法和属性
PivotResultRowAxis
包含与行轴相关的方法和属性
PivotFieldSet
多维数据集中定义的字段集
PivotField
多维数据集中定义的字段
ChartSpace
使用户连接到支持OLEDBProviderforOLAPServices8.0或更高版的任何OLAP数据源上,(也可连接到Excel电子数据表单和SQLServer、Access关系数据库)。
ChartSpace允许用户图形化显示数据并且将控件绑定到一个已存在的PivotTable或Spreadsheet。
ChCharts
ChChart对象集合
ChChart
ChartSpace中的单个图表,一个ChartSpace可容纳多达64个图表。
Figure5PivotTableComponent'
sProgrammaticInterface
类型
ActiveView
属性
表示一个活动的PivotTable布局。
该属性返回一个PivotView对象。
ColumnAxis
表示列轴中的字段。
返回一个PivotAxis对象。
ConnectionString
设置连接到AnalysisServices服务器的连接字符串,ConnectionString属性中的DataSource参数决定了OWC组件将要使用的连接协议。
DataAxis
表示数据轴的规模。
DataMember
设置控件将要从AnalysisServices请求的数据源名称。
它与多维数据集同名。
IncludedMembers
定义了PivotField内的数据成员。
该属性接受的参数为单一成员或成员数组。
IsIncluded
设置所包含的字段并激活PivotFieldSet。
RowAxis
表示行轴中的字段,返回PivotAxis对象。
XMLData
设置或返回当前用于PivotTable报表控件的XML数据。
有关报表的细节(格式和数据)均保存在XML数据中。
也包括了OLAP连接详细信息。
AddCustomGroupField
方法
为指定的PivotFieldSet添加一个定制的分组字段。
AddCustomGroupMember
为指定的PivotFieldSet添加一个定制的分组成员。
InsertFieldSet
在行或列轴中插入一个字段集。
CommandExecute
事件
在某个命令执行之后触发,ChartCommandIdEnum和PivotCommandId常量包含用于每个OWC组件所支持的命令清单。
Query
PivotTable激活某个查询时触发。
Figure6ChartComponent'
属性
为Chart控件定义数据源。
当设置另一个控件(如:
PivotTable或Spreadsheet)这样有效地绑定Chart控件到其它控件。
Type
象ChartChartTypeEnum枚举所定义的那样定义图表类型,默认类型为条形图。
Figure8ConnectingtoanOLAPDataSource
functioninitializePivotTable(strDataMember){
//ThisfunctioncallstheInitializePivotTableXML()Web
//method
variCallID=service.svcOLAP.callService
(onInitializePivotTableResult,
InitializePivotTableXML'
strDataMember);
}
functiononInitializePivotTableResult(result){
//ThisfunctionhandlestheInitializePivotTableXML()
//Webmethodresult
text=result.value;
//resultstring
//Evaluatereturnresult
if(!
result.error){
//AssigntheXMLtothePivotListXMLDatavalue
frm1.PivotTable1.XMLData=text;
else{
alert("
Unhandlederror-"
+result.errorDetail.code+
"
+result.errorDetail.string);
Figure9GenerateXMLDataforaPivotTableControl
<
WebMethod()>
PublicFunctionInitializePivotTableXML(ByVal_
strDataMemberAsString)AsString
Dimm_XMLAsString
DimstrOLAPConnAsString=_
ConfigurationSettings.AppSettings("
OLAPConnectionString"
)
Try
DimobjPTAsPivotTableClass=NewPivotTableClass
objPT.ConnectionString=strOLAPConn
objPT.DataMember=strDataMember
m_XML=objPT.XMLData
objPT=Nothing
CatcherrAsException
m_XML="
err>
&
err.Source&
-"
err.Message&
_
/err>
Finally
EndTry
Return(m_XML)
EndFunction
Figure10LoadCustomPivotTableReportWebMethod
PublicFunctionLoadCustomPivotTableReport(ByVal_
strCity1AsString,ByValstrCity2AsString)AsString
DimobjPTViewAsPivotView
DimfldCity,fldName,fldProdFamilyAsPivotField
DimfSetCustomers,fSetProductAsPivotFieldSet
objPT.DataMember="
Sales"
objPT.AllowFiltering=False
objPTView=objPT.ActiveView
objPTView.TitleBar.Caption="
CityComparisonofDrink
Definethecolumnelements
objPTView.ColumnAxis.InsertFieldSet(objPTView.FieldSets("
Time"
))
objPTView.ColumnAxis.FieldSets("
).Fields("
Year"
).Expanded=True
Definetherowelements
fSetCustomers=objPTView.FieldSets("
Customers"
objPTView.RowAxis.InsertFieldSet(fSetCustomers)
fSetCustomers.Fields("
Country"
).IsIncluded=False
StateProvince"
Name"
Definethemembersoftherowelements
fldCity=fSetCustomers.Fields("
City"
fldCity.IncludedMembers=NewObject(){strCity1,strCity2}
Excludeallotherfieldrowmembersinthefieldset
fSetProduct=objPTView.FieldSets("
Product"
objPTView.RowAxis.InsertFieldSet(fSetProduct)
fSetProduct.Fields("
ProductDepartment"
ProductCategory"
ProductSubcategory"
).IsIncluded=False
BrandName"
ProductName"
fldProdFamily=fSetProduct.Fields("
ProductFamily"
fldProdFamily.IncludedMembers="
Drink"
Definethemeasures
objPTView.DataAxis.InsertTotal(objPTView.Totals("
StoreSales"
objPTView.DataAxis.Totals("
).NumberFormat=_
Currency"
ReturntheXMLdatatotheclientsidescript
Figure11LoadtheXMLDataforaCustomReport
functionLoadSavedReport(){
//Purpose:
CallWebServicemethodtoloadthesaved
//report
variCallID=service.svcOLAP.callService(onLoadSavedReportResult,
LoadSavedReport'
'
OLAPReport1.xml'
);
functiononLoadSavedReportResult(result){
Thisfunctionhandlesthe
//wsOLAP.onLoadSavedReportResult()WebServiceresult
vartext=result.value;
Figure12JavaScriptandVBScriptEventHandler
scriptlanguage="
javascript"
event="
Query"
for="
PivotTable1"
>
{
varsLog=document.Form1.Text1.value+"
;
document.Form1.Text1.value="
QueryEventFired."
+sLog;
/script>
vbscript"
SubPivotTable1_CommandExecute(Command,Succeeded)
DimptConstants
SetptConstants=document.Form1.PivotTable1.Constants
ChecktoseeifthePivotTablelisthasbeen
refreshed.
IfCommand=ptConstants.plCommandRefreshThen
Writethecurrentdataandtimetothetextbox.
document.Form1.Text1.value=vbCrLf&
PivotTableLastRefreshedon"
Date&
at"
&
Time&
vbCrLf&
document.Form1.Text1.value
EndIf
EndSub
Figure13CreatingCustomGroups
PublicFunctionApplyCustomGrouping(ByVal_
strReportXMLDataAsString)AsString
Dimm_xmlAsString
DimfsTimeAsPivotFieldSet
DimfsHalfYearAsPivotField
objPT.XMLData=strReportXMLData
SetavariabletotheTimefieldset.
fsTime=objPTView.FieldSets("
Addacustomgroupfieldnamed"
Group1"
totheTimefield
set.
fsHalfYear=fsTime.AddCustomGr