本来已经请教过了,但是当时没有把问题说清楚,现在再请教各位高手。  
我想将文本数据的指定行转换成列,写入已经存在的EXCEL的指定列。先谢谢

解决方案 »

  1.   

    你的文本数据在哪儿?
    程序中?还是文本文件里?
    在VB里使用com方式打开excel文件,就可以直接向指定单元格写数据。只是没看明白你的指定文本是指什么。
      

  2.   

    我的数据在文本文件里,我想把数据导入EXCEL里,指定的某行变成列存入EXCEL的指定位置
      

  3.   

    '以下读出了文本文件所有行的内容
    dim file1,i,j as integer
    dim filename,temp() as string
    i=1
    filename="c:\test.txt" '要打开的文本文件
    open filename for input as file
    do while not eof(file1)
       line input #file1,temp(i) '整行读出,存入temp中
       i=i+1
    loop
    close file1
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '以下把文本文件写入EXCEL列中
    dim exlApp As Excel.Application     'EXCEL表格
    dim exlBook As Excel.Workbook       '工作簿
    dim exlSheet As Excel.Worksheet     '工作表
    dim exlFilename as string      '要写入的EXCEL文件名
    exlfilename="c:\test.xls"
    Set exlApp = New Excel.Application
    exlApp.Visible = False '不可见
    Set exlBook = exlApp.Workbooks.Open(exlfilename)
    Set exlSheet = exlBook.Worksheets(1)
    for j=1 to i
      exlsheet.cells(1,j)=temp(j) '(行,列)
    next j
    exlbook.save
    exlbook.close
    exlapp.quit
    set exlsheet=nothing
    set exlbook=nothing
    set exlapp=nothing
      

  4.   

    哦,上一贴是我回复的。其实你在上次代码的基础上修改一下就可以了,方法有许多,我还是修改一下上次的代码,希望你能读明白:  '读出文本内容
        Dim pFile As String
        Dim hFile  As Integer
        Dim sFile As String    pFile = "C:\test.txt"
        hFile = FreeFile()
        
        Open pFile For Binary As hFile
            sFile = Space(LOF(hFile))
            Get hFile, , sFile
        Close hFile
        
        '处理读取的数据:
        Dim fLines() As String
        Dim sRows() As String
        Dim sExcel() As String              '插入Excel的内容
        Dim i As Integer
        Dim row As Integer
         
        fLines = Split(sFile, vbCrLf) '按vbCrLf分组,得到行数据
        '比如指定第10行:
        sRows = Split(fLines(9), Chr(32))
        ReDim sExcel(UBound(sRows), 0)
        For i = 0 To UBound(sRows)
            If Trim(sRows(i)) <> "" Then
                sExcel(row, 0) = sRows(i)
                row = row + 1
            End If
        Next i
        
        '导入Excel
        Dim oExcel As Object
        Dim oBook As Object
        Dim oSheet As Object
        
        Set oExcel = CreateObject("Excel.Application")
        Set oBook = oExcel.Workbooks.open("C:\test.xls")
        Set oSheet = oBook.Worksheets(1)
        '指定插入G列
        oSheet.Range("G1").Resize(row, 1).Value = sExcel
        oExcel.Visible = True    Set oSheet = Nothing
        Set oBook = Nothing
        oExcel.Quit
        Set oExcel = Nothing