How can I coerce generated values in a PivotTable to adopt a specific format (Aspose Cells)? - formatting

I have code to create data fields (and then give their labels user-friendly strings) like so:
pivotTable.AddFieldToArea(PivotFieldType.Data, TOTALQTY_COLUMN);
pivotTable.AddFieldToArea(PivotFieldType.Data, TOTALPRICE_COLUMN);
pivotTable.AddFieldToArea(PivotFieldType.Data, AVGPRICE_COLUMN);
pivotTable.AddFieldToArea(PivotFieldType.Data, PERCENTOFTOTAL_COLUMN);
pivotTable.DataFields[0].DisplayName = "Total Packages";
pivotTable.DataFields[1].DisplayName = "Total Purchases";
pivotTable.DataFields[2].DisplayName = "Avg Purchase";
pivotTable.DataFields[3].DisplayName = "% of Total";
With this, I end up with values like so:
I want commas added to "Total Packages" so that for any value over 999, a comma will appear ("1,000" instead of "1000")
I also want dollar signs prepended to the "Total Purchases" values (so that, for instance, "14042.56" becomes "$14,042.56")
Also, I want "Avg Purchases" values such as "33.2" to instead be "33.20" (always two and exactly two values following the decimal point)
Finally, I want a percent sign appended to the "% of Total" values, so that "0.76" becomes "0.76%"
I thought the following might work:
pivotTable.DataFields[3].DataDisplayFormat = PivotFieldDataDisplayFormat.
...but there doesn't seem to be the right type of options for that to accomplish what I want.
What code is needed to make this work?

Please follow this thread. I have provided the sample code, source and output excel files for your reference. Let us know your feedback.
Thread Link
Note: I am working as Developer Evangelist at Aspose

Related

Report builder (SSRS) SWITCH statement blank values

For a report I'm building, there are fields that are dependent on a user selecting to add additional people to their policy (named in the dataset as dependent1, dependent2, etc).
We need to determine whether these dependants are adults or children for reporting. This will be done via DOB and a DateDiff which I understand
Currently, I can get the report to show ADULT or CHILD if data is present, however if there isn't any data I can't return a "" value, it just defaults to ADULT.
I'm using:
=Switch(DateDiff("yyyy", Fields!Dependant1DoB.Value, Fields!Policy_Start_Date.Value) < 18, "CHILD",
DateDiff("yyyy", Fields!Dependant1DoB.Value, Fields!Policy_Start_Date.Value) >= 18, "ADULT",
DateDiff("yyyy", Fields!Dependant1DoB.Value, Fields!Policy_Start_Date.Value), "")
I also created another column which uses the DateDiff between Fields!Dependant1DoB.Value & Fields!Policy_Start_Date.Value to show the number of years. This works and returns a number. however for some unknown reason where there's no data it still returns "2019" which may be effecting it? I've tried including this in the Switch statement (DateDiff("yyyy",Fields!Dependant1DoB.Value,Fields!Policy_Start_Date.Value)=2019, "")) but this still doesn't work.
Someone please help as this is driving me loopy!
You need to first check for nothing and then apply the switch function, example below:
=IIF(IsNothing(Fields!Dependent1DoB.Value),"",
Switch(
DateDiff("yyyy",Fields!Dependent1DoB.Value,Fields!Policy_Start_Date.Value)<18, "CHILD",
DateDiff("yyyy",Fields!Dependent1DoB.Value,Fields!Policy_Start_Date.Value)>=18, "ADULT"
)
)

WooCommerce: How to automatically select variation attribute dropdown field when there is only 1 option?

So I feel like this isn't too complicated of a request, but I simply can't figure it out. On my WooCommerce site, I have some variable products. There are 3 dropdown variation attributes in the following order (top to bottom): Color, Type, and Part Number. Each variation has a unique part number (only 1 part number per combination), so there is literally no need for the user to select the part number after they have chosen color & type. However, I need that part number to display for purposes of my product feed and so the customer can see the part number they have chosen by the previous 2 options.
My question is; since selecting a "Color" and "Type" narrows the final field ("Part number") down to only 1 option, how do I instruct WooCommerce to automatically select the single "part number" option that's available?
You can do this with JS:
jQuery('a.toggle_component').click(function(e){
if(!(jQuery(e.target).parents('.component').find('select.component_options_select > option[selected=selected]').val())) {
jQuery(e.target).parents('.component').find('select.component_options_select > option:nth-child(2)').attr('selected','selected');
jQuery(e.target).parents('.component').find('select.component_options_select').change();
}
});

Zoho Creator making a custom function for a report

Trying to wrap my head around zoho creator, its not as simple as they make it out to be for building apps… I have an inventory database, and i have four fields that I call to fill a field called Inventory Number (Inv_Num1) –
First Name (First_Name)
Last Name (Last_Name)
Year (Year)
Number (Number)
I have a Custom Function script that I call through a Custom Action in the form report. What I am trying to do is upload a CSV file with 900 entries. Of course, not all of those have those values (first/last/number) so I need to bulk edit all of them. However when I do the bulk edit, the Inv_Num1 field is not updated with the new values. I use the custom action to populate the Inv_Num1 field with the values of the other 4 fields.
Heres is my script:
void onetime.UpdateInv()
{
for each Inventory_Record in Management
{
FN = Inventory_Record.First_Name.subString(0,1);
LN = Inventory_Record.Last_Name.subString(0,1);
YR = Inventory_Record.Year.subString(2,4);
NO = Inventory_Record.Number;
outputstr = FN + LN + YR + NO;
Inventory_Record.Inv_Num1 = outputstr;
}
}
I get this error back when I try to run this function
Error.
Error in executing UpdateInv workflow.
Error in executing For Each Record task.
Error in executing Set Variable task. Unable to update template variable FN.
Error evaluating STRING expression :
Even though there is a First Name for example, it still thinks there is none. This only happens on the fields I changed with Bulk Edit. If I do each one by hand, then the custom action works—but of course then the Inv_Num1 is already updated through my edit on success functions and makes the whole thing moot.
this may be one year late, you might have found the solution but just to highlight, the error u were facing was just due to the null value in first name.
you just have put a null check on each field and u r good to go.
you can generate the inv_number on the time of bulk uploading also by adding null check in the same code on and placing the code on Add> On Submt.( just the part inside the loop )
the Better option would be using a formula field, you just have to put this formula in that formula field and you'll get your inventory_number autogenerated , you can rename the formula_field to Inv Number or whaterver u want.
Since you are using substring directly in year Field, I am assuming the
year field as string.else you would have to user Year.tostring().substring(2,4) & instead of if(Year=="","",...) you have to put if(Year==null , null,...);
so here's the formula
if(First_Name=="","",First_Name.subString(0,1))+if(Last_Name =="","",Last_Name.subString(0,1)) + if(Year=="","",Year.subString(2,4)+Number
Let me know ur response if u implement this.
Without knowing the datatype its difficult to fix, but making the assumption that your Inventory_Record.number is a numeric data item you are adding a string to a number:
The "+" is used for string Concatenation - Joiner but it also adds two numbers together so think "a" + "b" = "ab" for strings but for numbers 1 + 2 = 3.
All good, but when you do "a" + 2 the system doesn't know whether to add or concatenate so gives an error.

Where Clause with Alias Visual Basic & SQL

I have inherited a MS database, to work from, this database also links to other programs so I don't want to change the database tables itself.
I'm using Visual Basic 2010,
What I need to do is have a range of filters on this table and then one extra filter entered by the user.
e.g. they enter '50' and range '5' I need to search the dataset using the range of '45 to 55'
This is my code so far for the dataset:
SELECT [CUTTER NO]
,CUTTER_ID
,[SIZE-Inches]
,[MM-Across]
,[MM-Round]
,TYPE
,[LEADING EDGE]
,[CUTTER TYPE]
,ACROSS
,ROUND
,[WIDTH PAPERmm]
,[GAPS ACROSSmm]
,[GAPS ROUNDmm]
,[Serial Number]
,[T G]
,Repeat
,[Repeat MM]
,[L&G]
,Notes
FROM [Cutter List]
WHERE (TYPE <> 'DISCONTINUED')
AND (TYPE <> 'SPEC')
AND (CUTTER_ID <> NULL)
AND ([CUTTER TYPE] = 'MP')
AND (TYPE <> 'BUTT')
ORDER BY CUTTER_ID, [MM-Across]
What I need to type into this SQL is:
WHERE [MM-Across] LIKE #[MM-Across] and [MM-Round] LIKE #[MM-Round]
Which from what I can tell on the net is wrong as I cannot have [] in a where.
I even tried :
SELECT [MM-Across] AS mmacross
FROM [Cutter List]
WHERE ('mmacross' LIKE '#mmacross')
This it accepts but I get an different error appear saying
"The Schema returned by the new query differs from the base query."
What am I doing wrong? I don't understand the last error or how to avoid this.
Two things:
You can definitely have brackets "[..]" in WHERE clauses, they just have to be in the correct places (just like anywhere else), and
You cannot use the brackets in variable or parameter references, and that means that, unlike columns, you cannot have special characters in their names, like "-" in "#MM-Across", so just change your parameter names to something like "#MM_Across".
Note that the column names are fine, it's your parameter and/or variable names that you have to change (I cannot tell which these are from your snippet).
So instead of this:
WHERE [MM-Across] LIKE #[MM-Across] and [MM-Round] LIKE #[MM-Round]
Try this:
WHERE [MM-Across] LIKE #MM_Across and [MM-Round] LIKE #MM_Round
Of course, you will also have to change the parameter/variable names wherever they are declared and passed in. If you post the code that does this, I can show you how to change that also (thoguh it may be obvious by now).

regular expression to pull words beginning with #

Trying to parse an SQL string and pull out the parameters.
Ex: "select * from table where [Year] between #Yr1 and #Yr2"
I want to pull out "#Yr1" and "#Yr2"
I have tried many patterns, but none has worked, such as:
matches = Regex.Matches(sSQL, "\b#\w*\b")
and
matches = Regex.Matches(sSQL, "\b\#\w*\b")
Any help?
You're trying to put a word boundary after the #, rather than before. Maybe this:
\w(#[A-Z0-9a-z]+)
or
\w(#[^\s]+)
I would have gone with
/^|\s(#\w+)\s|$/
or if you didn't want to include the #
/^|\s#(\w+)\s|$/
though I also like joel's above, so maybe one of these
/^|\s(#[^\s]+)\s|$/
/^|\s#([^\s]+)\s|$/