Mozes to da uradis i sa referencom na Excel i onda manipulises sa copy i paste kao u Excelu.
Program se pokrece na Form1_Load
Fajlovi se nalaze u c:\test
Output je c:\test\output.xls
Takodje mi nije jasno da li hoces sve da ih kopiras u kolonu A ili u kolonu do kolone, videces dole opciju za obe verzije.
Kod mene ne radi bez ove zackoljice za Excel automation bug.
Srecno i javi jel pomoglo...
Pozdrav
J.
Citat:
[Project->Add Reference->Microsoft Excel 10.0 Object Library
Ovo je VB.net
Imports System.IO
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myXL As New Excel.ApplicationClass
Dim file As String
Dim files As String() = Directory.GetFiles("c:\test", "*.csv")
'Excel automation bug:
'client computer runs the English version of Microsoft Excel
'and the locale for the current user is configured for a language other than English
' myXL.UserControl = True
Dim oldCI As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
myXL.Visible = True
myXL.Workbooks.Open("c:\test\output.xls")
myXL.Range("A1").Select()
For Each file In files
With myXL
.Workbooks.Open(file, , , Format:=2) 'open as csv
.Range("A1").Select()
.Range(.Selection, .Selection.End(Excel.XlDirection.xlDown)).Select()
.Selection.Copy()
End With
myXL.Workbooks(1).Worksheets(1).Activate()
With myXL
.ActiveSheet.Paste()
'copy in columns
'.ActiveCell.Offset(0, 1).Select()
'copy in one row
.Selection.End(Excel.XlDirection.xlDown).Select()
.ActiveCell.Offset(1, 0).Select()
End With
myXL.Workbooks(2).Close()
Next
myXL.Workbooks(1).Close(SaveChanges:=True)
System.Threading.Thread.CurrentThread.CurrentCulture = oldCI
myXL.Quit()
myXL = Nothing
End Sub
End Class
[Ovu poruku je menjao Yellena dana 09.03.2006. u 15:00 GMT+1]
Entropy isn't what it used to be.