2011-07-14 11 views
0

私は、.csvファイルは、このVBAコードで引用符で出力されたExcelブックを持っている:phpmyadminの/ CSV(エクセル)の問題

"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 
"","","","","","","","","","","","","","","","","","" 
"","","","","","","","","","","","","","","","","","" 
"","","","","","","","","","","","","","","","","","" 
"","","","","","","","","","","","","","","","","","" 
"","","","","","","","","","","","","","","","","","" 
"","","","","","","","","","","","","","","","","","" 
"","","","","","","","","","","","","","","","","","" 
"","","","","","","","","","","","","","","","","","" 
"","","","","","","","","","","","","","","","","","" 
"","","","","","","","","","","","","","","","","","" 
"","","","","","","","","","","","","","","","","","" 
"","","","","","","","","","","","","","","","","","" 
"","","","","","","","","","","","","","","","","","" 
"","","","","","","","","","","","","","","","","","" 
"","","","","","","","","","","","","","","","","","" 
"","","","","","","","","","","","","","","","","","" 
"","","","","","","","","","","","","","","","","","" 
"","","","","","","","","","","","","","","","","","" 
"","","","","","","","","","","","","","","","","","" 
"","","","","","","","","","","","","","","","","","" 

'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 

これは、例えば、正しくファイルを出力します

まず空白のセルをすべて削除する方法を知りたいのですが、2番目にこれをphpMyAdminに入力するとすべて動作しますが、最初の列が欠落してしまい、望ましくない列名が入力されてしまいます。最初の名前の列をすべて入力してから、列名を忘れてしまいます。

私のサーバのphpMyAdminのバージョンは2.6.4です(私はその昔知っているが、私はそれについて何もできない)

しかし、また、あるバージョン3.3.9

である私のローカルサーバー上でこれを行いますUPDATE

ファイルを1列右に移動するだけで問題は解決しましたが、固定されていますが、他の2つの問題は依然として存在します。

答えて

1

あなたはここにあなたのVBAを変更できます。これに

'Set up Delimiters 
DELIMITER = "," 
QUOTE = """" 

:へ

'Set up Delimiters 
DELIMITER = ";" 
QUOTE = """" 

ためのphpMyAdminのデフォルトは、セパレータとして。あなたが空白のセルを削除するには、このVBAコードを使用することができ、あなたの第二の点にanswserで

Sub MacroNAME() 
    ActiveWorkbook.Save 
    Rows("1:1").Select 
    Selection.Cut 
    Sheets("sheetname").Select 
    Sheets.Add 
    ActiveSheet.Name = "Save" 
    ActiveSheet.Paste 
    Sheets("sheetname").Select 
    Rows("1:1").Select 
    Rows("1:1").RowHeight = 14.25 
    Selection.Delete Shift:=xlUp 
    Cells.Select 
    Selection.SpecialCells(xlCellTypeBlanks).Select 
    Selection.ClearContents 
    Columns("A:A").Select 
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove 
    Rows("1:1").Select 
    Selection.Delete Shift:=xlUp 
    Rows("2:2").RowHeight = 14.25 
    **Code Used above here** 
    Rows("1:1").Select 
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove 
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone 
    Rows("1:1").RowHeight = 0.1 
    Columns("A:A").Select 
    Selection.Delete Shift:=xlToLeft 
    Sheets("sheetname").Select 
    Rows("2:2").Select 
    Selection.Insert Shift:=xlDown 
    Rows("1:1").RowHeight = 10.5 
    Rows("1:1").RowHeight = 14.25 
    Sheets("Save").Select 
    Selection.Cut 
    Sheets("sheetname").Select 
    Rows("1:1").Select 
    ActiveSheet.Paste 
    Application.DisplayAlerts = False 
    Sheets("Save").Select 
    ActiveWindow.SelectedSheets.Delete 
    Application.DisplayAlerts = True 

これは、列見出しをクリアしますが、彼らはそれの最初の行で提供されます。

これをボタンに適用すると効果があります。

関連する問題