Utf-8 format

There will not be any problems if I run it on a personal computer, using tomcat server. But when I bring it to the Unix server, the font will crash as mentioned above! I do not understand why, because I can be sure that the lunix server has UTF-8

@HaiHung,

You may please use the APIs in FontConfigs to set font folder with Aspose.Cells latest version.

 //Add your font path.
 FontConfigs.setFontFolder("yourFontPath", true);
 Workbook wb = new Workbook(srcFile);
 wb.save(outFile.pdf);

If you only want to use the fonts in your font path, please replace the code:
FontConfigs.setFontFolder("yourFontPath", true);
to
FontConfigs.setFontExclusiveSources(new FontSourceBase[]{new FolderFontSource("youtFontPath", true)});

If the font file of one font that used by excel file cannot be found, we will try to find a font that can rendering the text.Also, you can control the font substitute by the

FontConfigs.setFontSubstitutes(String originalFontName, String[] substituteFontNames) API.

Hi
I’m using aspose for importing json to excel using java
but when save the workbook, the characters saved in the xls file are not utf-8…
I close the intellij and run it again and run the codes very soon, this time the file has been saved correctly!
but when I run it again the problem appears again!!!

please help me!!!

some part of my code is:

            URL obj = new URL(url);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
        // optional default is GET
        con.setRequestMethod("GET");
        //add request header
        con.setRequestProperty("User-Agent", "Mozilla/5.0");
        int responseCode = con.getResponseCode();
        System.out.println("\nSending 'GET' request to URL : " + url);
        System.out.println("Response Code : " + responseCode);
        BufferedReader in = new BufferedReader(
                new InputStreamReader(con.getInputStream()));
        String inputLine;
        

        StringBuffer response = new StringBuffer();
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();
        //سلام
        //print in String
        System.out.println(response.toString());

/*
//Read JSON response and print
JSONObject myResponse = new JSONObject(response.toString());
System.out.println(“result after Reading JSON Response”);
System.out.println("name- "+myResponse.getString(“name”));
*/
// aspose …
// Set Styles
CellsFactory factory = new CellsFactory();
Style style = factory.createStyle();
style.setHorizontalAlignment(TextAlignmentType.CENTER);
style.getFont().setColor(Color.getBlueViolet());
style.getFont().setBold(true);

// Set JsonLayoutOptions
JsonLayoutOptions options = new JsonLayoutOptions();
options.setTitleStyle(style);
options.setArrayAsTable(true);

        Workbook workbook = new Workbook();
        Worksheet worksheet = workbook.getWorksheets().get(0);

// Import JSON Data
JsonUtility.importData(String.valueOf(response), worksheet.getCells(), 0, 0, options);
String dataDir = “C:\firefox_Driver\temp\” +
“Aspose.Cells-for-Java-master\Examples\src\resources\RowsAndColumns\”;

// Save Excel file

        TxtSaveOptions txtOpt = new TxtSaveOptions(SaveFormat.EXCEL_97_TO_2003);
        txtOpt.setEncoding(Encoding.getUTF8());
        workbook.save(dataDir + "ImportingFromJson.xls",txtOpt);
        // Print message
        System.out.println("data updated successfully.");

no one can help me?!

@hamed0isu,

Thanks for the code segment and details.

You are mixing the things. The above lines of code are wrong. Please note, XLS file format has its own encoding standard and we cannot set encoding for it. So, kindly simply use the following line of code instead:
i.e.,

workbook.save(dataDir + “ImportingFromJson.xls”);

It seems your problem is due to JsonUtility.importData(String.valueOf(response), worksheet.getCells(), 0, 0, options); on your end. Anyways, we need JSON data to evaluate your issue (if you are still finding it). Please save your JSON data in some file, e.g “myfile.json” and zip the file and provide us, we will check it soon.

download.zip (49.5 KB)
dear Amjad
Thank you so much for your reply
I test the code without txt save option before and the result was the same.
the printed results in the intellij console is correct but I don’t know why when it save to xls this problem appears!
as I said when I run the code immoderately after opening intellij the xls saved correctly !

any way as your command I provide the json for more check with you… and thanks again for your soon response…

@hamed0isu,

I simply tested your scenario/ case in eclipse with the following sample code and template file using our latest version/fix Aspose.Cells for Java v20.6.x, it works absolutely fine and I do not find any issue with the output XLS file generated by Aspose.Cells:
e.g
Sample code:

	    // Set Styles
		CellsFactory factory = new CellsFactory();
		Style style = factory.createStyle();
		style.setHorizontalAlignment(TextAlignmentType.CENTER);
		style.getFont().setColor(Color.getBlueViolet());
		style.getFont().setBold(true);
		
		// Read File
		File file = new File("f:\\files\\download.json");
		BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
		String jsonInput = "";
		String tempString;
		while ((tempString = bufferedReader.readLine()) != null) {
		   jsonInput = jsonInput + tempString; 
		}
		bufferedReader.close();

		// Set JsonLayoutOptions
		JsonLayoutOptions options = new JsonLayoutOptions();
		options.setTitleStyle(style);
		options.setArrayAsTable(true);

		        Workbook workbook = new Workbook();
		        Worksheet worksheet = workbook.getWorksheets().get(0);
		// Import JSON Data
		JsonUtility.importData(jsonInput, worksheet.getCells(), 0, 0, options);

		// Save Excel file
		        workbook.save("f:\\files\\ImportingFromJson.xls");
		        // Print message
		        System.out.println("data updated successfully."); 

Please find attached the output file and check if it is ok.
files1.zip (85.1 KB)

Your issue is not related to Aspose.Cells by any means. I guess your issue is due to configurations or settings (regarding os, intellij itself or for your web application server, etc.) on your end, so you should sort out your issue by yourself. You should try your test case in some other machines and you will notice it works fine.

many thanks for taking time for me…
i try to run the code with coverage in intellij and now it works fine!

so what should I do to set the settings of the intellij?

@hamed0isu,

As I am not sure if the issue is with intellij, os or with browser type or web app server, so cannot help much. You should browse internet to search for relevant topics or pages by yourself for help.

ok thanks a lot
as a last question…
when I run the code with coverage the message shown in console is:
Process finished with exit code 0
but when I run without coverage the message is:
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use ‘–warning-mode all’ to show the individual deprecation warnings.
See Command-Line Interface

BUILD SUCCESSFUL in 8s
3 actionable tasks: 1 executed, 2 up-to-date

So is the problem caused by the gradle? I have other java class files in the project and they save some xls files without encoding problem despite of showing the mentioned warning!

@hamed0isu,

It seems the problem is caused by the gradle.

thanks again
I add the below code to the vmoptions of the intellij :
-Defile.encoding=utf-8
and the problem have been solved…

thank you again for your kind helps…

@hamed0isu,

You are welcome.