2012-04-23 1 views
0

Я прочитал данные из txt-файла, а затем сохранил его в целочисленном массиве. Теперь я хочу экспортировать этот массив на лист excel, но я не знаю, почему результат не прав. Пожалуйста, помогите мне.Как написать массив чисел в Excel в Visual Basic Excel

Input #1, n 

'Now construct the (n x n) matrix that will hold the problem and read in the problem from the input file 
ReDim ProbMatrix(1 To n, 1 To n) As Integer 

Dim someNumber As Integer 
Dim startPosition As Long 
Dim endPosition As Long 
Dim temp As String 

Do While Not (EOF(1)) 
    startPosition = Seek(1) '// capture the current file position' 
    Line Input #1, temp  '// read an entire line' 
    endPosition = Seek(1) '// determine the end-of-line file position' 
    Seek 1, startPosition '// jump back to the beginning of the line' 

    '// read numbers from the file until the end of the current line' 
    For i = 1 To n 
     For j = 1 To n 
      Do While Not (EOF(1)) And (Seek(1) < endPosition) 
       Input #1, someNumber 
       ProbMatrix(i, j) = someNumber 
       MsgBox ProbMatrix(i, j) 
      Loop 
     Next j 
    Next i   
Loop  
Close #1   

Dim NewProbMatrix() As Integer 
Dim act As Action 
NewProbMatrix = makeInitialSolution(ProbMatrix, n) 
Cells(1, 1) = n 
For i = 1 To n 
    For j = 1 To n 
     Cells(i + 1, j) = ProbMatrix(i, j) 
    Next 
Next 

Application.Save 
Workbooks.Close 
MsgBox ("Finished") 
+4

Что вы имеете в виду «результат не является правильным'? – markblandford

ответ

0

попробовать этот

With Thisworkbook.Activesheet 
.Cells(1, 1).value = n 
For i = 1 To n 
    For j = 1 To n 
     .Cells(i + 1, j).value = ProbMatrix(i, j) 
    Next 
Next 
End With 

Надеется, что это полезно, Приветствия

Смежные вопросы