05. september 2002 - 18:17
Der er
8 kommentarer og
1 løsning
CSV til Excel via ASP problem med komma.
Hejsa.
Jeg har nogle CSV filer jeg gerne vil have puttet ind i excel via ASP.
Mit problem ligger i at noget af det er beløb som indeholder komma "," så tror excel at den skal dele der, hvordan fixer jeg det?
eller er der en workaround?
05. september 2002 - 18:26
#3
Hvis man åbner filen i excel normalt, er der ingen problemer, men via asp bugger det.
05. september 2002 - 18:32
#5
'Option Explicit
Const vbNormal = 1 ' window style
DIM objXL, objWb, objR, objTab ' Excel object variables
DIM Title, Text, tmp, i, j, file, name
Title = "IW Test"
' here you may set the name of the file to be imported
file = "c:\iw_udtræk;.csv" ' must be located in the script folder
' create an Excel object reference
Set objXL = server.CreateObject ("Excel.Application")
' set the Excel window properties (not absolutely necessary)
objXL.WindowState = vbNormal ' Normal
objXL.Height = 300 ' height
objXL.Width = 400 ' width
objXL.Left = 40 ' X-Position
objXL.Top = 20 ' Y-Position
objXL.Visible = true ' show window
' Create new Workbook (needed for import the CSV file=
Set objWb = objXl.WorkBooks.Add
' Get the first loaded worksheet object of the current workbook
Set objWb = objXL.ActiveWorkBook.WorkSheets(1)
objWb.Activate ' not absolutely necessary (for CSV)
' Now invoke the import wizard
Set objTab = objWb.QueryTables.Add ("TEXT;" & file, objWb.Range("A1"))
' here comes the mumbo jumbo to set all the properties for the wizard
' Oh Microsoft, how do I wish to has a With feature or a possibility to
' pass named arguments to methods ....
objTab.Name = "Names"
objTab.FieldNames = True
objTab.RowNumbers = False
objTab.FillAdjacentFormulas = False
objTab.PreserveFormatting = True
objTab.RefreshOnFileOpen = False
objTab.RefreshStyle = 1 'xlInsertDeleteCells
objTab.SavePassword = False
objTab.SaveData = True
objTab.AdjustColumnWidth = True
objTab.RefreshPeriod = 0
objTab.TextFilePromptOnRefresh = False
objTab.TextFilePlatform = 2 'xlWindows
objTab.TextFileStartRow = 1
objTab.TextFileParseType = 1 'xlDelimited
objTab.TextFileTextQualifier = -4142 ' xlTextQualifierNone
objTab.TextFileConsecutiveDelimiter = False
objTab.TextFileTabDelimiter = True ' ### my delimiters
objTab.TextFileSemicolonDelimiter = True
objTab.TextFileCommaDelimiter = True
objTab.TextFileSpaceDelimiter = False
objTab.TextFileColumnDataTypes = Array(1, 1)
objTab.Refresh False
'WScript.Echo "We have loaded the worksheet"
' demonstrate how to read the column header values
'Text = "Worksheet " & objWb.name & vbCRLF
'Text = Text & "Column titles" & vbCRLF
'Text = Text & CStr(objWb.Cells(1, 1).Value) & vbTab
'Text = Text & CStr(objWb.Cells(1, 2).Value) & vbCRLF
' show some cell values (using the "hard coded method")
'Text = Text & CStr(objWb.Cells(2, 1).Value) & vbTab
'Text = Text & CStr(objWb.Cells(2, 2).Value) & vbCRLF
'Text = Text & CStr(objWb.Cells(3, 1).Value) & vbTab
'Text = Text & CStr(objWb.Cells(3, 2).Value) & vbCRLF
'Text = Text & CStr(objWb.Cells(4, 1).Value) & vbTab
'Text = Text & CStr(objWb.Cells(4, 2).Value) & vbCRLF
' Show results
'MsgBox Text, vbOkOnly+ vbInformation, Title
objXL.ActiveWorkbook.SaveAs "c:\test10.xls"
' I like to prevent the warning message about the unsaved data
' during closing Excel
objXL.DisplayAlerts = False ' prevent all message boxes
objXl.Quit ' Quit Excel
Set objXL = Nothing
min data:
ex:
"001","Text","100,59","1,520,15"