Click here to Skip to main content
15,888,037 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

Does anyone have any functional code to convert between this formats?

thank you.

What I have tried:

I tried create code according this code below but I have a problem with definition excel document.



Private Shared Sub Main()
    Console.WriteLine("Tutorial 39" & vbLf & "-----------" & vbLf)
    Dim workbook As ExcelDocument = New ExcelDocument()
    Console.WriteLine("Reading file C:\Samples\Tutorial30.csv")

    If workbook.easy_LoadCSVFile("C:\Samples\Tutorial30.csv") Then
        workbook.easy_getSheetAt(0).setSheetName("First tab")
        workbook.easy_addWorksheet("Second tab")
        Dim xlsTable As ExcelTable = (CType(workbook.easy_getSheetAt(1), ExcelWorksheet)).easy_getExcelTable()
        xlsTable.easy_getCell("A1").setValue("Data added by Tutorial39")

        For column As Integer = 0 To 5 - 1
            xlsTable.easy_getCell(1, column).setValue("Data " & (column + 1))
        Next

        Console.WriteLine(vbLf & "Writing file C:\Samples\Tutorial39.xls.")
        workbook.easy_WriteXLSFile("C:\Samples\Tutorial39.xls")
        Dim sError As String = workbook.easy_getError()

        If sError.Equals("") Then
            Console.Write(vbLf & "File successfully created.")
        Else
            Console.Write(vbLf & "Error encountered: " & sError)
        End If
    Else
        Console.WriteLine(vbLf & "Error reading file C:\Samples\Tutorial30.csv " & vbLf & workbook.easy_getError())
    End If

    Console.WriteLine(vbLf & "Press Enter to exit ...")
    workbook.Dispose()
    Console.ReadLine()
End Sub
Posted
Updated 30-May-19 4:07am
Comments
Richard MacCutchan 29-May-19 3:39am    
What problem do you have?
Member 13711215 29-May-19 3:58am    
first problem is my language. Im from Czech Republic and we use special char e.g. Ž,Š,Č. Export from datagrid to csv look like, e.g. Životná is exported as Životná. Can you help me with this problem? File.WriteAllBytes(filePath, Encoding.Unicode.GetBytes(sb.ToString)).
The main problem is that i don't know how to convert csv to xls.
How do I get started correctly to make the transfer including these characters?
Richard MacCutchan 29-May-19 10:00am    
No, Životná is exported as Životná. It is when you try to display it that it gets shown as Životná, because whatever app displays it does not know that it should use the Czech character set.

Excel can open (valid) CSV files; there is no need for you to "convert".

.net - Open a CSV file in Excel via C#? - Stack Overflow[^]
 
Share this answer
 
 Private Sub konverze(sender As Object, e As EventArgs) Handles konvertovat_btn.Click
        Dim datestart As Date = Date.Now
        Dim dateEnd As Date = Date.Now
        Dim msExcelApplication As New Microsoft.Office.Interop.Excel.Application()
        Dim xlApp As New Excel.Application
        Dim path As String = "M:\Úsek financí\power BI\Helios Evidence vyrobnich operaci\říjen2018.xlsx"
        Dim xlWorkbook As Excel.Workbook = xlApp.Workbooks.Add()

        Dim xlWorksheet As Excel.Worksheet = CType(xlWorkbook.Sheets("List1"), Excel.Worksheet)
        xlWorksheet.Cells(1, 1) = ""
        If File.Exists("M:\Úsek financí\power BI\Helios Evidence vyrobnich operaci\říjen2018.xlsx") Then
        Else
            xlWorksheet.SaveAs(path)
            xlWorkbook.Close()
            xlApp.Quit()

        End If
        Dim workBook As Microsoft.Office.Interop.Excel.Workbook = msExcelApplication.Workbooks.Open("M:\Úsek financí\power BI\Helios Evidence vyrobnich operaci\říjen2018.xlsx", 0, False, Type.Missing, "", "", True, Type.Missing, Type.Missing, True, False, Type.Missing, True, False, False)
        'workBook.WebOptions.Encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingOEMNordic
        Try
            Dim workSheet As Microsoft.Office.Interop.Excel.Worksheet = workBook.Sheets(1)
            With workSheet.QueryTables.Add(Connection:="TEXT;M:\Úsek financí\říjen2018.csv", Destination:=workSheet.Range("$A$1"))
                .Name = "říjen2018"
                .FieldNames = True
                .RowNumbers = False
                .FillAdjacentFormulas = False
                .PreserveFormatting = True
                .RefreshOnFileOpen = False
                .SavePassword = False
                .RefreshStyle = Microsoft.Office.Interop.Excel.XlCellInsertionMode.xlInsertDeleteCells
                .SaveData = True
                .AdjustColumnWidth = True
                .RefreshPeriod = 0
                .TextFilePromptOnRefresh = False
                '.TextFilePlatform = 1250
                .TextFileStartRow = 1
                .TextFileParseType = Microsoft.Office.Interop.Excel.XlTextParsingType.xlDelimited
                .TextFileTextQualifier = Microsoft.Office.Interop.Excel.XlTextQualifier.xlTextQualifierDoubleQuote
                .TextFileConsecutiveDelimiter = False
                .TextFileTabDelimiter = False
                .TextFileSemicolonDelimiter = False
                .TextFileCommaDelimiter = True
                .TextFileSpaceDelimiter = False
                .TextFileTrailingMinusNumbers = True
                .Refresh(BackgroundQuery:=False)
            End With
        Catch ex As Exception
            Console.WriteLine(ex.ToString())
            Console.ReadLine()
        Finally
            'workBook.SaveAs(Name)
            workBook.Close(True)
            msExcelApplication.Quit()
            Marshal.ReleaseComObject(xlWorksheet)
            Marshal.ReleaseComObject(xlWorkbook)
            Marshal.ReleaseComObject(workBook)
            Marshal.ReleaseComObject(xlApp)
end sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900