У меня есть книга Excel, где файл .csv выводится с кавычками с этим кодом VBA:
'Set up Delimiters
DELIMITER = ","
QUOTE = """"
'Set up file to save, ask user for name
GetFileName = InputBox("Enter Name for semi-colon delimited file: (Do not enter file extension)", "FILENAME")
'CurrentPath = Application.ActiveWorkbook.Path
PathtoUse = "C:\Users\David\Desktop\"
FileNametoUse = PathtoUse & GetFileName & ".csv"
'Find cells to cycle through
With ActiveSheet.UsedRange
LastRow = .Cells(.Cells.Count).Row
LastCol = .Cells(.Cells.Count).Column
End With
'Assign a handle to next file#
FileNum = FreeFile
'Open and write to file named above
Open FileNametoUse For Output As #FileNum
'Cycle through rows and cols
For Each CurrentRow In Range("A1:A" & LastRow)
With CurrentRow 'Now cycle through each cell in the row
For Each CurrentCell In Range(.Cells, Cells(.Row, LastCol))
'If the cell contains Non-Numeric (IsNumeric=False) then put quotes around the info
If IsNumeric(CurrentCell.Text) = False Then
CellData = QUOTE & CurrentCell.Text & QUOTE
Else 'The cell contains numeric, use contents as is
CellData = CurrentCell.Text
End If
'as the code cycles, keep adding each col info to string
LineOutput = LineOutput & DELIMITER & CellData
Next CurrentCell
'Remove the first 2 chars in the line (since the delimiter is put in first)
LineOutput = Mid(LineOutput, 2)
'Print the line to the file
Print #FileNum, LineOutput
'Clear out the variable
LineOutput = Empty
End With
Next CurrentRow
'Close the file
Close #FileNum
Это выводит файл правильно, например:
"FirstName","Surname","YBC","BTBA","JTE","EnteringAverage","DOB","Game1","Game2","Game3","Game4","Game5","Game6","Game7","Game8","IndividualTotal","Average","TeamTotal"
"David","Passmore","Bowlplex Poole",116016,193,179,"05/08/1994",203,254,211,195,187,184,200,267,1701,212.63,3178
"Callum","Bailey","Bowlplex Poole",016015,185,189,"30/05/1996",175,145,195,117,201,265,221,158,1477,184.63,3178
"","","","","","","","","","","","","","","","","",""
"","","","","","","","","","","","","","","","","",""
"","","","","","","","","","","","","","","","","",""
"","","","","","","","","","","","","","","","","",""
"","","","","","","","","","","","","","","","","",""
"","","","","","","","","","","","","","","","","",""
"","","","","","","","","","","","","","","","","",""
"","","","","","","","","","","","","","","","","",""
"","","","","","","","","","","","","","","","","",""
"","","","","","","","","","","","","","","","","",""
"","","","","","","","","","","","","","","","","",""
"","","","","","","","","","","","","","","","","",""
"","","","","","","","","","","","","","","","","",""
"","","","","","","","","","","","","","","","","",""
"","","","","","","","","","","","","","","","","",""
"","","","","","","","","","","","","","","","","",""
"","","","","","","","","","","","","","","","","",""
"","","","","","","","","","","","","","","","","",""
"","","","","","","","","","","","","","","","","",""
"","","","","","","","","","","","","","","","","",""
Во-первых, яЯ хочу знать, как удалить все пустые ячейки, и, во-вторых, когда я ввожу это в phpMyAdmin, все это работает, НО пропускает первый столбец и вводит имена столбцов, которые мне не нужны, поэтому я хочу, чтобы он ввел всеимя столбца, а затем я хочу, чтобы он пропустил имена столбцов.
Версия моего сервера phpmyadmin 2.6.4 (я знаю, что он старый, но я ничего не могу с этим поделать)
Но он также делает это на моем локальном сервере версии 3.3.9
ОБНОВЛЕНИЕ
Я исправил проблему с первым столбцом, просто переместив файл на один столбец вправо, так что это исправлено, но две другие проблемы все еще существуют.