vsflexgrid应用Word文档下载推荐.docx
《vsflexgrid应用Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《vsflexgrid应用Word文档下载推荐.docx(13页珍藏版)》请在冰豆网上搜索。
PrivateSubCmdDel_Click()
Iffg.Row<
>
0Thenfg.RemoveItem(fg.Row)
fg.Refresh
EndSub
PrivateSubCmdAdd_Click()
OnErrorResumeNext
Adodc1.Recordset.AddNew
IfErr.Number<
0ThenMsgBoxErr.Description
PrivateSubCmdUpdate()
Adodc1.Recordset.UpdateBatchadAffectAllChapters
PrivateSubCmdCancel_Click()
Adodc1.Recordset.CancelBatch
fg.DataRefresh
PrivateSubForm_Load()
Adodc1.ConnectionString="
FILENAME="
&
App.Path&
"
\conn.dsn"
Adodc1.LockType=adLockBatchOptimistic
Adodc1.RecordSource="
Your_Tablename"
Setfg.DataSource=Adodc1
1、打印vsflexgrid可以使用vsprinter打印控件。
跟vsflexgrid配套使用效果不错。
2、导出EXECL,可以使用grid.savegrid的方法。
用savegrid的方法,在导出execl时,如果碰到类似于银行帐号的列如:
“6465456665”,导到EXECL中就不这样显示了,这个问题还不知道怎么解决?
?
另外也可以写代码(这个方法比较实用,但慢一些):
DimexcelAppAsExcel.Application
SetexcelApp=NewExcel.Application
IfexcelAppIsNothingThen
SetexcelApp=CreateObject("
Excel.application"
)
ExitSub
excelApp.Visible=True
Me.MousePointer=vbHourglass
excelApp.Workbooks.Add
WithexcelApp.ActiveSheet
DimiAsInteger,jAsInteger
Fori=1ToGrid1.rows
Forj=1ToGrid1.Cols
.Cells(i,j).value="
'
&
Grid1.TextMatrix((i-1),(j-1))'
加上“'
”号则可以解决上面savegrid中银行帐号的导出问题。
Nextj
DoEvents
Nexti
EndWith
Me.MousePointer=vbDefault
SetexcelApp=Nothing
EXCEL同Vsflexgrid通过
最近很多的朋友,都想知道EXCEL怎样同VSflexgrid交换数据。
实际上,利用“复制”、“粘贴”菜单即可实现。
具体如下:
(1)在Vsflexgrid上弹出右键菜单
PrivateSubgrid1_MouseDown(ButtonAsInteger,ShiftAsInteger,XAsSingle,yAsSingle)
ifButton=2ThenPopupMenumnutccd
(2)设置各菜单的内容
A复制
Clipboard.Clear
Clipboard.SetTextgrid1.Clip
B剪切
DimrowcAsLong
DimrowzAsLong
DimcolcAsLong
dimcolzAsLong
dimiaslong
dimsaslong
Ifgrid1.Rows=1ThenExitSub
Ifgrid1.RowSel>
grid1.rowThen
rowc=grid1.row
rowz=grid1.RowSel
rowc=grid1.RowSel
rowz=grid1.row
Ifgrid1.ColSel>
grid1.ColThen
colc=grid1.Col
colz=grid1.ColSel
colc=grid1.ColSel
colz=grid1.Col
Fori=rowcTorowz
Fors=colcTocolz
grid1.TextMatrix(i,s)="
Next
C粘贴(精华部分)
DimiAsLong
DimsAsLong
DimmAsLong
DimtAsLong
t=Len(Clipboard.GetText)
Ift=0ThenExitSub
Fori=1Tot
IfMid(Clipboard.GetText,i,1)=Chr(9)Thens=s+1
IfMid(Clipboard.GetText,i,1)=Chr(13)Thenm=m+1
Ifs/(m+1)+grid1.Col>
grid1.Cols-1Then
grid1.ColSel=grid1.Cols-1
grid1.ColSel=s/(m+1)+grid1.Col
Ifgrid1.row+m>
grid1.Rows-1Then
grid1.RowSel=grid1.Rows-1
grid1.RowSel=grid1.row+m
grid1.Clip=Clipboard.GetText
VSFlexGrid常用属性或方法:
.FixedRows=1'
固定几行
.FixedCols=1'
固定几列
.Editable=True'
允许修改
.AllowUserResizing=flexResizeBoth'
可调整行/列
.FocusRect=flexFocusNone'
无虚框
.SelectionMode=flexSelectionListBox'
焦点选中样式
.BackColor=RGB(255,255,255)'
单元背景色
.BackColorSel=vbBlue'
单元选择色
.BackColorFixed=RGB(208,192,160)'
固定单元色
.BackColorAlternate=RGB(255,250,230)'
间隔行背景色
.GridColor=RGB(245,240,210)'
单元线条色
.ForeColor=RGB(0,0,0)'
单元前景色(字符色)
.RowHeightMin=260'
最小行高
.RowHeightMax=800'
最大行高
.ColHeightMin=50'
最小列宽
.ColHeightMax=3000'
最大列宽
.ColWidth(Col)=1000'
指定列宽
.RowHeight(Row)=260'
指定行高
.TextMatrix(Row,Col)="
Text"
'
指定单元字符
.Text="
选定单元字符
.MergeCol(Col)=True'
允许合并列
.MergeRow(Row)=True'
允许合并行
.MergeCells=0|1|2|3|4|5|6'
合并选项
.Cell(选项准则,Row1,Col1,Row2,Col2)'
选择部分的相应准则值
.EditCell'
当移动到当前单元时自动选择
.EditSelStart'
移动到单元时的光标位置
.MousePointer'
设置对象的鼠标指针样式O.A=0到15|99
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
几个特殊的属性方法的使用:
FormatString属性:
管道符格式化字符串示例:
下面定义对齐方式同字意,列宽窄同距离
VSG1.FormatString="
^中|<
左|>
右|>
右|^中"
+++++++++++++++++++++++++
搜索(查找)表格中符合条件的行:
FindRow属性:
该属性返回一个行值
MsgBoxVSG1.FindRow(关键词,[指定行],[指定列],[敏感],[精度])
关键词:
String,表示要搜索的字符串
指定行/指定列:
Long,表示只在指定的行或列中找
敏感:
Boolean,
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
限制只能在指定列输入(这里默认倒数第2列)
PrivateSubVSG1_BeforeRowColChange(ByValOldRowAsLong,_
ByValOldColAsLong,ByValNewRowAsLong,_
ByValNewColAsLong,CancelAsBoolean)
VSG1.Editable=flexEDKbd
IfVSG1.Redraw<
flexRDNoneAndNewCol<
VSG1.Cols-2Then
Cancel=True
VSG1.SelectNewRow,VSG1.Cols-2
限制不能编辑某些列:
(这里限制第1列和第3列)
PrivateSubVSG1_RowColChange()
IfVSG1.Col=1OrVSG1.Col=3Then
VSG1.FocusRect=flexFocusNone
VSG1.Editable=flexEDNone
SendKeys"
{TAB}"
{ENTER}"
或:
{RIGHT}"
VSG1.EditCell'
自动选择单元内容
VSG1.EditSelStart=0[选到最前]|1[选到指定]|Len(VSG1.Text)[选到最后]
对齐方式(-1标示所有)
.ColAlignment(-1)=flexAlignLeftCenter|flexAlignCenterCenter|flexAlignRightCenter
示例1:
(最后一行的第3列靠右对齐)
VSG1.SelectVSG1.Rows-1,2
VSG1.CellAlignment=flexAlignRightCenter
示例2:
VSG1.Row=VSG1.Rows-1:
VSG1.Col=1
示例3:
VSG1.Cell(flexcpAlignment,VSG1.Rows-1,1,VSG1.Rows-1,3)=flexAlignRightCenter
本对象拖放:
PrivateSubVSG1_MouseDown(ButtonAsInteger,_
ShiftAsInteger,XAsSingle,YAsSingle)
VSG1.Drag
VSG1.DragIcon=LoadPicture("
D:
\Icon.ico"
VSG1.DragRowVSG1.RowSel
或从其它对象拖:
PrivateSubVSG2_MouseDown(ButtonAsInteger,_
VSG2.OLEDrag
VSG1.OLEDropMode=flexOLEDropAutomatic
PublicSubVSGridCount(OptionalSelRowAsLong,OptionalSelColAsLong)
DimXAsLong,iAsLong
DimHj1,Hj2,Hj3AsString
ConstA1=-922337203685477#,A2=922337203685477#
OnErrorGoToErrTransact
WithfrmFG.VSG1
X=.Rows-1
.MergeCells=flexMergeFree
.MergeRow(X)=True
.Cell(flexcpText,X,0,X,1)="
合计"
If.Rows=3Then
.TextMatrix(X,0)=0
.Cell(flexcpText,X,2,X,14)="
.Cell(flexcpText,X,16,X,17)="
¥0.00"
Hj1=Val(.Aggregate(flexSTSum,2,2,X-1,2))
Hj2=Val(.Aggregate(flexSTSum,2,16,X-1,16))
Hj3=CurrencyToStr(Hj2)
Fori=2ToX-2
Hj1=Hj1+Val(.TextMatrix(i,15))
IfVal(.TextMatrix(i,16))>
0Then
Hj2=Hj2+Val(.TextMatrix(i,15))*Val(.TextMatrix(i,16))
IfHj2<
=A1OrHj2>
=A2Then
GoToErrTransact
.TextMatrix(X,2)=Hj1
.Cell(flexcpText,X,3,X,15)=IIf(Hj3="
"
Hj3)
.Cell(flexcpText,X,16,X,17)=Format(Hj2,"
.Cell(flexcpAlignment,X,2,X,14)=flexAlignLeftCenter
.SelectX,3
.CellAlignment=flexAlignLeftCenter
IfSelRow>
1AndSelCol>
0Then.SelectSelRow,SelCol
ErrTransact:
MsgBox"
你输入的数字过大无法计算!
请修改!
!
------------------------------------------------
将数字转换为大写金额的函数:
FunctionCurrencyToStr(ByValNumberAsCurrency)AsString
Number=Val(Trim(Number))
IfNumber=0ThenCurrencyToStr="
:
ExitFunction
Dimstr1AryAsVariant,str2AryAsVariant
str1Ary=Split("
零壹贰叁肆伍陆柒捌玖"
str2Ary=Split("
分角元拾佰仟万拾佰仟亿拾佰仟万拾佰"
DimaAsLong,bAsLong'
循环基数
Dimtmp1AsString'
临时转换
Dimtmp2AsString'
临时转换结果
DimPointAsLong'
小数点位置
IfNumber<
=-922337203685477#OrNumber>
=922337203685477#Then
ExitFunction
tmp1=Round(Number,2)
tmp1=Replace(tmp1,"
-"
)'
先去掉“-”号
Point=InStr(tmp1,"
."
取得小数点位置
IfPoint=0Then'
如果有小数点,最大佰万亿
b=Len(tmp1)+2'
加2位小数
b=Len(Left(tmp1,Point+1))'
包括点加2位小数
先将所有数字替换为中文
Fora=9To0Step-1
tmp1=Replace(Replace(tmp1,a,str1Ary(a)),"
Fora=1Tob
b=b-1
IfMid(tmp1,a,1)<
Ifb>
UBound(str2Ary)ThenExitFor
tmp2=tmp2&
Mid(tmp1,a,1)&
str2Ary(b)
Iftmp2="
ThenCurrencyToStr="
〓下面为非正式财务算法,可以去掉〓
Fora=1ToLen(tmp2)
tmp2=Replace(tmp2,"
零亿"
亿零"
零万"
万零"
零仟"
零"
零佰"
零拾"
零元"
元"
零零"
亿万"
亿"
〓上面为非正式财务算法,可以去掉〓
IfPoint=1Thentmp2="
+tmp2
0Thentmp2="
负"
IfPoint=0Thentmp2=tmp2+"
整"
CurrencyToStr=tmp2
EndFunction
Cell属性的使用:
Cell的作用是给以选定区块的特定的设置值,具体值可参阅相应属性值。
语法:
Cell(条件准则,Row1,Col1,Row2,Col2)=相应准则值
其中的“条件准则”有以下准则常数,根据准则的不同而设置相应准则的值:
flexcpAlignment对齐方式
flexcpBackColor背景色
flexcpChecked选择框
flexcpCustomFormat格式设置
flexcpData日期
flexcpFloodColor颜色
flexcpFloodPercent背景色
flexcpFont字体
flexcpFontBold粗体
flexcpFontItalic斜体
flexcpFontName字体名
flexcpFontSize字体大小
flexcpFontStrikethru删除线
flexcpFontUnde