Hello,
I am currently using syncfusion_flutter_xlsio/xlsio.dart for creating Excell files.
Everything is going well, except...
here are the parts of codes that concern the column
Hi Huart,
Greetings from Syncfusion.
Currently, while importing the list, formula calculation is not supported. So, kindly use the following code snippet before saving the workbook to get the proper values for the Formulas.
Code Snippet:
|
int firstRow = sheet.getFirstRow(); int firstCol = sheet.getFirstColumn(); int lastRow = sheet.getLastRow(); int lastCol = sheet.getLastColumn();
for (int row = firstRow; row <= lastRow; row++) { for (int col = firstCol; col <= lastCol; col++) { if (sheet.getRangeByIndex(row, col).formula != null) { sheet.getRangeByIndex(row, col).calculatedValue; } } }
final List<int> bytes = workbook.saveAsStream(); saveAsExcel(bytes, 'Sample.xlsx'); workbook.dispose(); |
kindly try this and let us know if the solution helps.
Regards,
Ramya.
Hello and thank you for your help :)
I added the loops but that doesn't work either..
maybe the problem comes from saving the file?
I see you are using: saveAsExcel, but I don't have this method, am I missing a package?
Here is how I did:
Hi Huart,
There is no issue with the file saving method. We have attached the sample which was tried at our end. Kindly share a sample illustrating the issue or else modify the following sample and reproduce the issue which would help us to proceed further.
Sample link - https://www.syncfusion.com/downloads/support/directtrac/general/ze/F175086903936161
And kindly confirm the Syncfusion Package version which you are using at your end.
Regards,
Ramya.
thank you for your example,
I tried and indeed, when I work with DateTime, it works correctly.
The problem with this format is that it is limited to 24:00.
In my case, I have to make a total calculation of hours worked, example over a week: 38:00 of work.
I tried with the Duration type, but that doesn't work either.
Do you have an idea ?
I feel that we are getting closer to the goal :)
a big thank-you
Hi Huart,
We suggest you apply the [h]: mm number format to the cell to achieve your requirement. Please find the code snippet below.
Code Snippet:
|
sheet.getRangeByName('A4').numberFormat = '[h]:mm'; |
Kindly try and let us know if the suggested code snippet helps.
We appreciate your patience.
Regards,
Ramya.
it doesn't work either :(
If anyone has had this problem before..
I reproduced the problem in the Excel file you sent me :
Hi Huart,
Assigning the time values in cells setText method considers the value as the Text. So, the sum of these cell values is 0, which is incorrect. This is the same behavior in Microsoft Excel also.
But, when you assign values to cells with DateTime format in Microsoft Excel, the sum won’t be 0, but the result is different from what you expect. Please look at the below screenshot.
This behavior can be achieved in XlsIO with the below code snippet.
Code Snippet:
|
// Create a new Excel Document. final Workbook workbook = Workbook();
// Accessing sheet via index. final Worksheet sheet = workbook.worksheets[0];
///I need to add up working hours ///to calculate a weekly total sheet.getRangeByName('A1').setDateTime(DateTime(1900, 1, 1, 10, 0, 0)); sheet.getRangeByName('A2').setDateTime(DateTime(2000, 1, 1, 20, 0, 0)); sheet.getRangeByName('A3').setDateTime(DateTime(2000, 1, 1, 2, 0, 0));
//Creating a new style with all properties. final Style style = workbook.styles.add('Style1'); style.fontSize = 13; style.hAlign = HAlignType.right; style.vAlign = VAlignType.center; style.bold = false; style.numberFormat = 'hh:mm';
sheet.enableSheetCalculations();
sheet.getRangeByName('A1:A3').cellStyle = style;
///expected result ///A5 = 10:00 + 20:00 + 02:00 = 32:00 /// ///obtained result ///A5 = 00:00 sheet.getRangeByName('A5').setFormula("=SUM(A1:A3)"); sheet.getRangeByName('A5').numberFormat = '[hh]:mm';
int firstRow = sheet.getFirstRow(); int firstCol = sheet.getFirstColumn(); int lastRow = sheet.getLastRow(); int lastCol = sheet.getLastColumn();
for (int row = firstRow; row <= lastRow; row++) { for (int col = firstCol; col <= lastCol; col++) { if (sheet.getRangeByIndex(row, col).formula != null) { sheet.getRangeByIndex(row, col).calculatedValue; } } }
final List<int> bytes = workbook.saveAsStream(); workbook.dispose(); |
Kindly try this code snippet and let us know if this helps.
Regards,
Ramya.
Hello,
sorry but I don't understand how DateTime works, when I apply your code, I get a totally improbable result:
on your side, do you manage to perform the calculation of the weekly working hours and have the right result?
Hi Huart,
We are checking the feasibility of providing the sample for your requirement and will get back to you with details on May 31, 2022.
We appreciate your patience.
Regards,
Ramya
Hi Huart,
We have prepared the sample to convert the text format to time format. Now the sum value is proper kindly try the sample and let us know if it helps.
Sample link - https://www.syncfusion.com/downloads/support/directtrac/general/ze/F175086-TimeIssue294712625
Regards,
Ramya.
wooooow
it works !!!!
a huge thank you to you <3
You're welcome, Huart. We are glad!!! that the provided suggestion helped you, please feel free to contact us if you need any other assistance.
Regards,
Ramya