'保存表格数据
'函数:SaveFile
'参数:MsgObj Mshfelxgrid控件名,FileName 加载的文件名
'返回值:=True 成功.=True 失败.
Public Function SaveFile(MsgObj As Control, FileName As String) As Boolean
'/保存文件
Dim FileID As Long, ConTents As String
Dim A As Long, B As Long
Dim RowMax As Long, ColMax As Long
Dim FixRows As Long, FixCols As Long
Dim OleRow As Long, OleCol As Long
Dim SFmtStr As String
Dim strColWidth As String
On Error Resume Next
With MsgObj
.Redraw = False
FixRows = .FixedRows: FixCols = .FixedCols
RowMax = .Rows - 1: ColMax = .Cols - 1
.FixedRows = 0: .FixedCols = 0
FileID = FreeFile
Open FileName For Output As #FileID
ConTents = RowMax + 1 & "|" & ColMax + 1 & "|" & FixRows & "|" & FixCols & "|"
Print #FileID, ConTents '保存总的行数和列数.
For A = 0 To .ColMax
strColWidth = strColWidth & .ColWidth(A) & "|"
Next
Print #FileID, Left$(strColWidth, Len(strColWidth) - 1) '保存各列的宽度.
For A = 0 To RowMax
.Row = A: .Col = 0
.RowSel = A: .ColSel = ColMax
ConTents = .Clip
Print #FileID, ConTents
Next A
Close #FileID
.FixedRows = FixRows: .FixedCols = FixCols
.Redraw = True
End With
SaveFile = (Err.Number = 0)
Err.Clear
End Function
将Grid存为文本文档
最新推荐文章于 2023-06-12 23:11:34 发布