We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose.Cells is giving space separated characters when reading cell values in Java

Hi Aspose Team,

When trying to read a excel file the text coming as like below

V e n d o r N u m b e r

This is the expected output - Vendor Number

This is the code we use to extract the excel file

LoadOptions loadOptions = new LoadOptions(LoadFormat.AUTO);|
FileFormatInfo finfo = FileFormatUtil.detectFileFormat(fileName);|
if (finfo.getFileFormatType() == FileFormatType.UNKNOWN)|
{|
loadOptions = new TxtLoadOptions(LoadFormat.TAB_DELIMITED);|
}|
loadOptions.setMemorySetting(MemorySetting.MEMORY_PREFERENCE);|
Workbook w = new Workbook(fileName,loadOptions);|

Please suggest to get the word without any spacing between the characters

Please find the attachment
character_spacing_prblm.zip (214 Bytes)

@hruser,

Please notice, I am able to reproduce the issue as you mentioned by using the following sample code with your template file. I found Aspose.Cells is giving space separated characters when reading from a Tab Delimited file:
e.g.
Sample code:

LoadOptions loadOptions = new LoadOptions(LoadFormat.AUTO);
        FileFormatInfo finfo = FileFormatUtil.detectFileFormat("f:\\files\\character_spacing_prblm.xls");
        if (finfo.getFileFormatType() == FileFormatType.UNKNOWN)
        {
            loadOptions = new TxtLoadOptions(LoadFormat.TAB_DELIMITED);
        }
        loadOptions.setMemorySetting(MemorySetting.MEMORY_PREFERENCE);
        Workbook w = new Workbook("f:\\files\\character_spacing_prblm.xls",loadOptions);

        System.out.println(w.getWorksheets().get(0).getCells().get("A1").getStringValue());//V e n d o r   N u m b e r

I have logged a ticket with an id “CELLSJAVA-43503” for your issue. We will look into it soon.

Once we have an update on it, we will let you know.

1 Like

@hruser,

We evaluated your issue further and found it is not an issue with the APIs. Please try to set the encoding before loading the template file. See the following sample code that works fine as we tested:
e.g.
Sample code:

 TxtLoadOptions loadOptionsTxt = new TxtLoadOptions(LoadFormat.TAB_DELIMITED);
        loadOptionsTxt.setEncoding(Encoding.getUnicode());

        LoadOptions loadOptions = new LoadOptions(LoadFormat.AUTO);
        FileFormatInfo finfo = FileFormatUtil.detectFileFormat("f:\\files\\character_spacing_prblm.xls");
        if (finfo.getFileFormatType() == FileFormatType.UNKNOWN)
        {
            loadOptions = new TxtLoadOptions(LoadFormat.TAB_DELIMITED);
            loadOptions = loadOptionsTxt;
        }
        loadOptions.setMemorySetting(MemorySetting.MEMORY_PREFERENCE);
        Workbook w = new Workbook("f:\\files\\character_spacing_prblm.xls",loadOptions);

        System.out.println(w.getWorksheets().get(0).getCells().get("A1").getStringValue());

Hope, this helps a bit.

Hi @Amjad_Sahi

Thank you for the code, yeah its working now.

One more query, do we have any method to detect the encoding of a excel file?
If yes can you please give me a sample code.

@hruser,

Well, I am afraid, it is not possible to auto detect the encoding type of a text format like CSV or tab delimited, therefore you have to explicitly set the encoding using the TxtLoadOptions class.