导出数据到CSV文件

我们有超过65,536行的数据导出(写入).csv文件。 但是Excel(CSV)仅支持65,536。 Excel支持多个工作簿,所以我们可以将数据写入多个工作簿。 但是CSV也不支持这个function。 有没有其他的方式来做到这一点。 有没有人可以帮忙?

如果可能的话,您可以将数据写入多个CSV文件。 CSV基本上只是一个文本文件,所以没有像多张表等东西

也许你可以使用Excel文件(xls)和多张表。 根据您使用的语言(例如Apache POI for Java),存在用于编写Excel文件的库。

如果您的目标是Excel,有许多库可以帮助生成CSV文件的xls文件。 对他们来说是易于使用的CarlosAg.ExcelXmlWriter.dll 。

下面最初是为Excel2003编写的,但是当我迁移到2007年时,COMDLG32不被支持,所以烦恼的是你只是得到一个InputBox。 我有一段时间没有使用它,所以它可能需要一点修改,但希望指出你在正确的方向。

Sub OpenCSV_bysheet() 'No COMDLG32.OCX Dim fileNo As Integer Dim tempRow, fileNm As String Dim tempRowNo, x, y As Long Dim CommaOnOff As Boolean fileNm = InputBox("Please input Drive:\Path\Filename.csv", , CurDir & "\*.csv") If fileNm = "" Then Exit Sub For x = 1 To Len(fileNm) If Mid(fileNm, x, 1) = "*" Or Mid(fileNm, x, 1) = "?" Then Exit Sub Next x ' UserForm1.CommonDialog1.CancelError = True ' UserForm1.CommonDialog1.Flags = cdlOFNHideReadOnly ' UserForm1.CommonDialog1.Filter = "Comma Separated Value files (*.csv)|*.csv|All Files (*.*)|*.*" On Error GoTo errorTrap ' UserForm1.CommonDialog1.ShowOpen ' fileNm = UserForm1.CommonDialog1.Filename fileNo = FreeFile tempRowNo = 0 x = 0 y = 0 On Error Resume Next Workbooks.Add (xlWBATWorksheet) Application.ScreenUpdating = False Open fileNm For Input As fileNo Do While Not EOF(fileNo) Line Input #fileNo, tempRow If x Mod 65536 = 0 And x > 0 Then Sheets.Add x = 0 End If x = x + 1 y = y + 1 ActiveCell.Cells(x, 1).Value = tempRow ActiveCell.Cells(x, 1).TextToColumns Destination:=ActiveCell.Cells(x, 1), _ DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, _ Tab:=False, Semicolon:=False, Comma:=True, Space:=False, Other:=False Application.StatusBar = y Loop Close fileNo errorTrap: Application.ScreenUpdating = False Application.StatusBar = False End Sub