I am able to load data from a local JSON file and displays it in a dropdown menu. Then select a value from the dropdown and the application will display the corresponding "Range Array" and "Force Array" from the JSON data. I want to generate a Excel sheet with the data that was selected from the dropdown. The generated Excel would need to look like this:
At this moment i am able to generate a Excel that displays the values but without Chart.
The Excel looks like this:
But at this point i think how i am generating the Excel is not the right way.
Because the Excel would need to look like this, so that i could generate a Chart .
Follows the code that i have to read from the local Json and generating the Excel:
```
```
The Json looks like this:
```
```
Thanks in advance for some help
I changed my code to this:
To get a XY Scatter Chart.
```
```
I am getting the Excel like this:
Now i have two situation that i do not understand.
To get the Excel result shown in the picture, on this line.
1:
```
sheet.getRangeByName('A${i + 2}').setText(rangeArray[i].toString());
```
I am declaring it to setText (String). If i declare it to setValue i do not get the result shown in the picture.
2:
```
```
I am declaring
sheet.getRangeByName('A1:B5')
as hardcoded. At the Json file exampel that i gave it is ok like this. In the example there are 4 values. But it can be 4 or more or less values. I need a way to get all values depending on the quantity
Hi Carlos,
To get the cell values as per the Excel image from your initial update, we
suggest using SetValue method to set cell values. Now, you have used SetValue
method for force array values whereas SetText method is for range array values.
So, the range array values are treated as text instead of numbers. This is the
expected behavior of Excel.
To set both values as numbers and find the dynamic array length, please refer to the code snippet below.
void generateExcellOfficeChart(String fileName) async { // Create a new Workbook final Workbook workbook = Workbook(); final Worksheet sheet = workbook.worksheets[0];
sheet.showGridlines = true; // Enable-Disable Gridlines
// Setting value in the cell. sheet.getRangeByName('A1').setText('Range'); sheet.getRangeByName('B1').setText('Force');
//Create an instances of chart collection. final ChartCollection charts = ChartCollection(sheet);
// Add the chart. final Chart chart1 = charts.add(); var rangeArray = data["measure"].firstWhere((item) => item["count"] == selectedCount)["range_array"]; var forceArray = data["measure"].firstWhere((item) => item["count"] == selectedCount)["force_array"];
for (var i = 0; i < rangeArray.length; i++) { sheet.getRangeByName('A${i + 2}').setValue(rangeArray[i]); sheet.getRangeByName('B${i + 2}').setValue(forceArray[i]); }
// Set Chart Type. chart1.chartType = ExcelChartType.line; chart1.dataRange = sheet.getRangeByName('A1:B${forceArray.Length}');
// set charts to worksheet. sheet.charts = charts;
// Save the workbook to a file final List<int> bytes = workbook.saveAsStream(); workbook.dispose(); await saveAndLaunchFile(bytes, '$fileName.xlsx'); } |
Please share the required sample Excel document with us. It will help us to create a sample from our end to achieve your requirement.
Thanks,
Rahul.
Hi Rahul,
Thanks a lot for your reply.
I follow your suggestions.
This:
chart1.dataRange = sheet.getRangeByName('A1:B${forceArray.Length}');
I changed to this:
chart1.dataRange = sheet.getRangeByName('A1:B${forceArray.length}');
To make it work.
Follows the Excel and Json file.
Hi Carlos,
We are glad that the provided suggestion helped you. Please get back to us if you need any further assistance.
Note: If that post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Hi Rahul,
Thanks for the help.
It was my fault.
To set both values as numbers and find the dynamic array
length, please refer to the code snippet below.
chart1.dataRange = sheet.getRangeByName('A1:B${forceArray.length}');
This is working.
But i continuo not be able to create a Excel like i provided, if i use this:
sheet.getRangeByName('A${i + 2}').setValue(rangeArray[i]);
sheet.getRangeByName('B${i + 2}').setValue(forceArray[i]);
Only if i define like this: But setText is not what i want.
sheet.getRangeByName('A${i + 2}').setValue(rangeArray[i]);
sheet.getRangeByName('B${i + 2}').setText(forceArray[i]);
Hi Carlos,
Please share the current Excel document in which the problem is occurring, as well as the expected output Excel file, so that we can analyze the issue and provide a solution as soon as possible.
Hi Rahul,
Thanks for the reply.
I am sharing the Measure Zip File.
There are 4 files.
Hi Carlos,
The expected Excel document you shared contains a scatter with a line and marker chart created for the data provided, but you used Flutter XlsIO to create a line chart, which is the expected output according to Microsoft Excel behavior.
Currently, we do not have support for creating scatter charts in Flutter XlsIO, and we have logged a feature request for this support. However, we do not have any immediate plans to implement this feature in the near future.
You can track the status of this feature report through the below feedback link.
https://www.syncfusion.com/feedback/41039/support-for-creating-scatter-charts-in-flutter-xlsio
Note: To get the expected result, Should set "Range" column values to text using the setText method.
Regards,
Rahul
Hi Rahul,
Thanks a lot for the reply.
To get the expected result, i set "Range" column values to text using the setText method.
Hi Carlos,
You’re welcome. Kindly
let us know if you need any further assistance.