Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 将数据导出到CSV文件_.net_Excel_Csv - Fatal编程技术网

.net 将数据导出到CSV文件

.net 将数据导出到CSV文件,.net,excel,csv,.net,Excel,Csv,我们有65536行以上的数据要在.csv文件中导出(写入)。但Excel(CSV)仅支持65536。Excel支持多个工作簿,因此我们可以在多个工作簿中写入数据。但CSV也不支持此功能。有没有其他方法可以做到这一点。有人能帮上忙吗?如果您的目标是Excel,有许多库可以帮助生成xls文件而不是CSV。其中之一就是易于使用。如果可能的话,您可以将数据写入多个CSV文件。CSV基本上只是一个文本文件,所以没有多张纸之类的东西 也许你可以使用Excel文件(xls)和多张工作表。根据您使用的语言(例如

我们有65536行以上的数据要在.csv文件中导出(写入)。但Excel(CSV)仅支持65536。Excel支持多个工作簿,因此我们可以在多个工作簿中写入数据。但CSV也不支持此功能。有没有其他方法可以做到这一点。有人能帮上忙吗?

如果您的目标是Excel,有许多库可以帮助生成xls文件而不是CSV。其中之一就是易于使用。

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


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

下面的内容最初是为Excel2003编写的,但当我迁移到2007年时,COMDLG32不受支持,令人烦恼的是,您只得到了一个输入框。我已经有一段时间没有使用它了,所以它可能需要一些修改,但希望能为您指明正确的方向

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

你为什么不直接把它写进电子表格呢?Microsoft.Office.Interop.Excel命名空间。