Reading CSV File with Multiple Encodings
Aspose.Cells provides the TxtLoadOptions.is_multi_encoded property, which you need to set to true to load your CSV file with multiple encodings properly.
The following screenshot shows a sample CSV file that contains two lines. The first line is in ANSI encoding and the second line is in Unicode encoding
Input file |
---|
![]() |
The following screenshot shows the XLSX file converted from the above CSV file without setting the TxtLoadOptions.is_multi_encoded property to true. As you can see, the Unicode text was not converted properly.
Output file 1: no accommodation made for multiple encoding |
---|
![]() |
The following screenshot shows the XSLX file converted from the above CSV file after setting the TxtLoadOptions.is_multi_encoded property to true. As you can see, the Unicode text is now converted properly.
Output file 2: IsMultiEncoded is set to true |
---|
![]() |
Below is the sample code that converts the above CSV file into XLSX format properly.
from aspose.cells import SaveFormat, TxtLoadOptions, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
filePath = dataDir + "MultiEncoded.csv" | |
# Set Multi Encoded Property to True | |
options = TxtLoadOptions() | |
options.is_multi_encoded = True | |
# Load the CSV file into Workbook | |
workbook = Workbook(filePath, options) | |
# Save it in XLSX format | |
workbook.save(filePath + ".out.xlsx", SaveFormat.XLSX) |