将Grid存为文本文档

来源:互联网 发布:al是什么软件 编辑:程序博客网 时间:2024/05/17 07:55
'保存表格数据'函数: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.ClearEnd Function

0 0
原创粉丝点击