Number formatting in pivot table with Aspose.Cells - aspose

I am creating a pivot table in excel sheet by aspose.cells. I want the values to be formatted as Accounting, with a symbol, a comma and 2 decimal places. Is this possible with aspose.cells? Please suggest how to do this with Aspose.Cells and c#.

If you need Accounting number formatting for the PivotField, you may try to use the following numeric formatting using PivotField.Number attribute instead.
pivotTable.DataFields[0].Number = 43; //You may also try it with 44 if it suits your needs.
Alternatively you may try to use the following formatting string for NumberFormat custom attribute of PivotField. You may also check in MS Excel to get your desired custom strings to try with NumberFormat property.
_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(#_)
If you still face any confusion/issue, can you please share the sample Excel file in which you may manually set the desired number formatting for the Pivot Table fields in MS Excel, and share the file with us, so that we can test the scenario at our end.
Furthermore, can you please share the code/sample application with the template files (input, output and expected output file etc.). The files can also be shared in Aspose.Cells product support forum.

Please try using PivotField.NumberFormat property to specify his desired formatting, see the code segment below for reference:
//Specify the number formatting to the first data field added.
pivotTable.DataFields[0].NumberFormat = "$#,##0.00";
Moreover, we also recommend you use our latest version of Aspose.Cells for .NET 7.4.0 in which we made some more enhancements regarding PivotTables.
PS, I am working as Support developer / Technical Evangelist at Aspose.

Related

How I extract number from text in Google Data Studio?

I tried this but it's still showing null as you can see in the screen. Please help to solve this.
REGEXP_EXTRACT(X,"[0-9]*[0-9]")
It can be achieved using the Calculated Field below which uses the REGEXP_EXTRACT function to extract the numbers and the CAST function to ensure that it's a Number field:
CAST(REGEXP_EXTRACT(Attività, "(\\d+)") AS NUMBER )
Google Data Studio Report and GIF to elaborate:

Google Sheets Data Validation not rejecting invalid input

I have a sheet where I control provided services with columns filled with execution and conclusion dates.
These columns have data validation for invalid dates and also, for the user not to input weekend days or holidays (which is listed on another page of the same spreadsheet). So it has to be custom formula validation.
Validation formula:
=AND(ISDATE(K2)=TRUE;K2>=J2;WEEKDAY(K2)<>1;WEEKDAY(K2)<>7;COUNTIF(Holidays!$A:$A;"="&K2)=0)
also tried
=AND(ISDATE(K2)=TRUE;K2>=J2;WEEKDAY(K2)<>1;WEEKDAY(K2)<>7;ISNA(MATCH(K2;Holidays!$A:$A;0))=TRUE)
and also tried using INDIRECT("Holidays!$A:$A") on both options
***Column K has the data validation and Conclusion date is the input. Column J has execution dates. And row 1 has titles.
The problem:
data validation input rejection seems to work fine for the first couple of hours, sometimes a full day, but after this random period of time, it stops working. Actually it does work, but with the red flag, even though "Reject input" option is still checked.
My guess is that the problem resides on the reference being in another sheet, but I don't see any other way to do this, as including the holiday list to the main sheet would pollute it and hiding columns wouldn't be as practical since users update the list constantly.
Is there a way to make it work?
P.S. Conditional Formatting used to return error even when using INDIRECT for external reference but now Google seems to have fixed it.
Hope someone can help me.
custom formula for data validation:
=(ISDATE(A1))*
(WEEKDAY(A1, 2)<>6)*
(WEEKDAY(A1, 2)<>7)*
(NOT(REGEXMATCH(TO_TEXT(A1), TEXTJOIN("|", 1, INDIRECT("Sheet2!H:H")))))
custom formula for conditional formatting (valid green):
=(ISDATE(A1))*
(WEEKDAY(A1, 2)<>6)*
(WEEKDAY(A1, 2)<>7)*
(NOT(REGEXMATCH(TO_TEXT(A1), TEXTJOIN("|", 1, INDIRECT("Sheet2!H:H")))))
custom formula for conditional formatting (invalid red):
=((ISDATE(A1))*
(WEEKDAY(A1, 2)<>6)*
(WEEKDAY(A1, 2)<>7)*
(NOT(REGEXMATCH(TO_TEXT(A1), TEXTJOIN("|", 1, INDIRECT("Sheet2!H:H")))))=0)*
(A1<>"")
spreadsheet demo
I find the issue happens when the user is copying and pasting into the cell, instead of typing in, as part of a larger section of information. This breaks up the data validation into "pieces" because the copy and paste doesn't come with the data validation. I'm not sure if this is the case with you, but it may mean training users to copy and paste values only or only hard keying the information.

How can I resolve INDEX MATCH errors caused by discrepancies in the spelling of names across multiple data sources?

I've set up a Google Sheets workbook that synthesizes data from a few different sources via manual input, IMPORTHTML and IMPORTRANGE. Once the data is populated, I'm using INDEX MATCH to filter and compare the information and to RANK each data set.
Since I have multiple data inputs, I'm running into a persistent issue of names not being written exactly the same between sources, even though they're the same person. First names are the primary culprit (i.e. Mary Lou vs Marylou vs Mary-Lou vs Mary Louise) but some last names with special symbols (umlauts, accents, tildes) are also causing errors. When Sheets can't recognize a match, the INDEX MATCH and RANK functions both break down.
I'm wondering how to better unify the data automatically so my Sheet understands that each occurrence is actually the same person (or "value").
Since you can't edit the results of an IMPORTHTML directly, I've set up "helper columns" and used functions like TRIM and SPLIT to try and fix instances as I go, but it seems like there must be a simpler path.
It feels like IFS could work but I can't figure how to integrate it. Also thinking this may require a script, which I'm just beginning to study.
Here's a simplified example of what I'm trying to achieve and the corresponding errors: Sample Spreadsheet
The first tab is attempting to pull and RANK data from tabs 2 and 3. Sample formulas from the Summary tab, row 3 (Amelia Rose):
Cell B3: =INDEX('Q1 Sales'!B:B, MATCH(A3,'Q1 Sales'!A:A,0))
Cell C3: =RANK(B3,$B$2:B,1)
Cell D3: =INDEX('Q2 Sales'!B:B, MATCH(A3,'Q2 Sales'!A:A,0))
Cell E3: =RANK(D3,$D$2:D,1)
I'd be grateful for any insight on how to best index 'Q2Sales'!B3 as the correct value for 'Summary'!D3. Thanks in advance - the thoughtful answers on Stack Overflow have gotten me this far!
to counter every possible scenario do it like this:
=ARRAYFORMULA(IFERROR(VLOOKUP(LOWER(REGEXREPLACE(A2:A, "-|\s", )),
{REGEXEXTRACT(LOWER(REGEXREPLACE('Q2 Sales'!A2:A, "-|\s", )),
TEXTJOIN("|", 1, LOWER(REGEXREPLACE(A2:A, "-|\s", )))), 'Q2 Sales'!B2:B}, 2, 0)))

Excel international date formatting

I am having problems formatting Excel datetimes, so that it works internationally. Our program is written in C++ and uses COM to export data from our database to Excel, and this includes datetime fields.
If we don't supply a formatting mask, some installations of Excel displays these dates as Serial numbers (days since 1900.01.01 followed by time as a 24-hour fraction). This is unreadable to a human, so we ha found out that we MUST supply a date formatting mask to be sure that it displays readable.
The problem - as I see it - is that Excel uses international formatting masks. For example; the UK datetime format mask might be "YYYY-MM-DD HH:MM".
But if the format mask is sent to an Excel that is installed in Sweden, it fails since the Swedish version of the Excel uses "ÅÅÅÅ-MM-DD tt:mm".
It's highly impractical to have 150 different national datetime formatting masks in our application to support different countries.
Is there a way to write formatting masks so that they include locale, such that we would be allowed to use ONE single mask?
Unless you are using the date functionality in Excel, the easiest way to handle this is to decide on a format and then create a string yourself in that format and set the cell accordingly.
This comic: http://xkcd.com/1179/ might help you choose a standard to go with. Otherwise, clients that open your file in different countries will have differently formatted data. Just pick a standard and force your data to that standard.
Edited to add: There are libraries that can make this really easy for your as well... http://www.libxl.com/read-write-excel-date-time.html
Edited to add part2: Basically what I'm trying to get at is to avoid asking for the asmk and just format the data yourself (if that makes sense).
I recommend doing the following: Create an excel with date formatting on a specific cell and save this for your program to use.
Now when the program runs it will open this use this excel file to retrieve the local date formatting from the excel and the specified cell.
When you have multiple formats to save just use different cells for them.
It is not a nice way but will work afaik.
Alteratively you could consider creating an xla(m) file that will use vba and a command to feed back the local formatting characters through a function like:
Public Function localChar(charIn As Range) As String
localChar = charIn.NumberFormatLocal
End Function
Also not a very clean method, but it might do the trick for you.

Spreadsheets: insert into columns as if a stack

First: I know this would be much easier if it was a .CSV but that is not possible (I'd 'a written the code in the time I wrote this post).
I want to insert numbers given by the user along with a time-stamp into a spreadsheet. There will be a graph in the spreadsheet that automatically generates based on columns a and b, hence the need to not be a .CSV. Column A holds Double-Floats of range 0 through 500 and Column B holds Date and Time information. Inserted rows must be at the top, thus pushing all existing data down by one row, each time.
I've been writing this manually and I think its time to stop doing that. I don't really care what language it is done in, but I would prefer C/C++ using at most the boost libraries. All libraries MUST be open-source. OS is Linux and input should from terminal or at least be given to the program as a parameter, such that the user's input could be piped into the program.
I found this, but I'm not sure if it is the best method as I'm not necessarily locked into python.
Insert row into Excel spreadsheet using openpyxl in Python
Thanks for any and all help.
Have you tried this? A C library that read Excel (xls) files: http://libxls.sourceforge.net.
Hope this meet your need.
An alternative: http://www.libxl.com, more powerful but not open source.