In continuation of a previous thread, I've reached pretty close to where I want and have learned a lot. I'm under CF10 on a MSSQL Server 2008 environment. I have a report I'm generating using cfspreadsheet and then spitting out values based on whether a user has an app enabled it will be output as "Yes" and if not output as "No" in the excel spreadsheet.
Problem is, I need to make it a little easier on the eye and so I wanted to see if it was possible to apply conditional formatting to where if the 3 columns with 3 different apps is Y then it will be green and if N it will be red.
Any suggestions or examples would be great, thanks!
Like I mentioned in your other thread, if you return bit values (not strings), it is simple to apply a custom cell format. But you must use the spreadsheet functions, rather than cfspreadsheet (which does not support custom formatting).
Here is an expanded example to demonstrate how you could incorporate conditional color formatting:
<cfscript>
// build sample query
// note: values must be numeric and NOT text/varchar
qData = queryNew("");
queryAddColumn(qData, "AppNameAlpha", "bit", listToArray("0,0,1,0,1"));
queryAddColumn(qData, "AppNameBeta", "bit", listToArray("1,1,0,0,1"));
// create sample sheet
sheet = spreadsheetNew();
spreadsheetAddRows(sheet, qData);
// apply colorized yes/no format
spreadsheetFormatColumns(sheet, {dataformat='[Green]"Y";;[Red]"N"'}, "1-2");
spreadsheetWrite(sheet, "c:/path/to/sheet.xls", true);
</cfscript>
The "dataformat" uses the first three sections of Excel's custom number formatting: <positive><negative><zero>. Translated:
[Green]"Y"; // <positive values>: display "Y" in green
; // <negative values>: do nothing extra
[Red]"N" // <zero values>: display "N" in red
The function you are looking for is SpreadsheetFormatCell()
Related
I have a column of values that are a number out of 10. So, it could be 2/10, 3/10, 4/10 and so on, all the way up to 10/10. To be clear, these are not dates, but simply showing how many questions the student answered correctly out of 10.
I'm trying to use conditional formatting to highlight them a certain color depending upon the score they got. For 9/10 and 10/10, I'm wanting to use a certain color, but it doesn't seem to be working with REGEXMATCH or with OR. Also wanting to highlight all scores that are 6/10 or lower. I know that I could make this work by applying conditional formatting for each and every score with text contains but the problem I'm finding is that it thinks it's a date.
Is there a way to match multiple scores out of 10 using REGEXMATCH?
Link to Sheet
select column and change formatting to Plain text
now you can use formula like:
=REGEXMATCH(A1; "^9|10\/")
I'm running into an issue when trying to compare data across two sheets to find discrepancies - specifically when it comes to comparing start and end times.
Right now, the "IF" statement in my screenshot is executing perfectly, except when a time is involved - it's reading those cells as decimals instead (but only sometimes).
I've tried formatting these cells (on the raw data AND on this "Discrepancies" report sheet) so that they are displayed as a "HH:MM am/pm" time, but the sheet is still comparing the decimal values.
Is there anything that I can add to this function to account for a compared value being a time instead of text, and having that text be compared for any discrepancies? I cannot add or change anything to the raw data sheets, the only thing I can edit is the formula seen in the screenshot I provided.
See the highlighted cells in my screenshot - this is the issue I keep running into. As you can see, there are SOME cells (the non-highlighted ones) that are executing as intended, but I'm unsure why this isn't the case for the whole spreadsheet when I've formatted everything the same way using the exact same formula across the whole sheet.
For example, the values in cell N2 is "8:00 AM" on both sheets, so the formula should just display "8:00 AM" in that cell (and NOT be highlighted) since there is no discrepancy in the cells between both sheets it's comparing. But instead, it's showing both times as a decimal with the slightest difference between them and is suggesting a difference where there technically isn't (or shouldn't be) one.
Please help!
Screenshot of original spreadsheet for reference
---EDIT (added the below):
Here is a view-only version of a SAMPLE SHEET that displays the issue I'm having:
https://docs.google.com/spreadsheets/d/1BdSQGsCajB3kOnYxzM3sl-0o3iTvR3ABdHpnzYRXjpA/edit?usp=sharing
On the sample sheet, the only cells that are performing as intended are C2, E2, G2, I2, K2, K6, or any cells that contain text like "Closed". Any of the other cells that have a time in both raw data tabs appears to be pulling the serial numbers for those times instead of correctly formatting it into "HH:mm AM/PM".
A quick tour of how the SAMPLE SHEET is set up:
User enters raw data into the "MicrositeRawData" and "SalesforceRawData" tabs.
Data is pulled from the "SalesforceRawData" tab into the "CleanedUpSalesforceData" tab using a QUERY that matches the UNIQUE ID's from the "MicrositeRawData" sheet, so that it essentially creates a tab that's in the same order and accounts for any extraneous data between the tabs (keep in mind this is a sample sheet and that the original sheet I'm using includes a lot more data which causes a mismatch of rows between the sheets which makes the QUERY necessary).
The "DISCREPANCIES" tab then compares the data between the "MicrositeRawData" and "CleanedUpSalesforceData" tabs. If the data is the same, it simply copies the data from the "MicrositeRawData" cell. But if the data is NOT the same, it lists the values from both sheets and is conditionally formatted to highlight those cells in yellow.
If there is data on the "MicrositeRawData" tab that is NOT included on the "SalesforceRawData" tab, the "DISCREPANCIES" tab will notate that and highlight the "A" cell in pink instead of yellow (as demonstrated in "A5").
try in B2:
=IF(MicrositeRawData!B2=CleanedUpSalesforceData!B2, MicrositeRawData!B2,
"MICROSITE: "&TEXT(MicrositeRawData!B2, "h:mm AM/PM")&CHAR(10)&
"SALESFORCE: "&TEXT(CleanedUpSalesforceData!B2, "h:mm AM/PM"))
update
delete all formulae from range B2:O10 and use this in B2:
=ARRAYFORMULA(IF(TO_TEXT(MicrositeRawData!B2:O10)=
TO_TEXT(CleanedUpSalesforceData!B2:O10), MicrositeRawData!B2:O10,
"MICROSITE: "&TEXT(IF(MicrositeRawData!B2:O10="",
"", MicrositeRawData!B2:O10), "h:mm AM/PM")&CHAR(10)&
"SALESFORCE: "&TEXT(IF(CleanedUpSalesforceData!B2:O10="",
"", CleanedUpSalesforceData!B2:O10), "h:mm AM/PM")))
I'm trying to write a simple formula for Google Sheets. The logic is as follows:
if(it is a specific date & it is today){fill cell color with this color}
I know this needs to be done in the conditional formatting section but I am unable to get it right.
I've tried:
if(TODAY(),RegExMatch("Tuesday May 2, 2017"))
RegExMatch("Tuesday May 2, 2017") AND IF(TODAY())
IF(TODAY() AND RegExMatch("Tuesday May 2, 2017"))
but none of those work and return errors such as 'parse & invalid' when attempting to write it in the cell box.
REGEXMATCH can be used in Conditional formatting (eg) but it seems way overkill here. Please select the relevant range (I am assuming ColumnA - populated with 'true' dates, not text) and clear any existing CF rules from it. Format, Conditional formatting..., Format cells if... Custom formula is and
=and(A1=today(),A1=42858)
with fill colour of choice and Done.
Here 42858 happens to be the index number for today, but would be replaced with that for your specific date.
Have you tried just getting the value of TODAY()? It returns the date in mm/dd/yyyy format. Your RegExMatch will always fail.
You don't need to use any formula. Use this guide to see how you can use conditional formatting rules on individual or multiple cells. The correct way to do what you want to do is to select a cell, click on Format -> Conditional formatting... -> Format cells if... -> Date is -> today
If you're referring to the cell box in the 'Custom formula' section, you simply need to write =TODAY().
Not sure I'm following exactly, but if your date is in col A:
=AND(DATEVALUE(a1)=datevalue("5/2/2017"),DATEVALUE(a1)=DATEVALUE(today()))
this seems to work. The date has to be parseable to date by sheets for DATEVALUE to work though.
Image has the column in an IF as well setting 1 or 0 just an example of the logic too.
I've seen this post, but there does look to be a resolution. Anyway, I'm using ColdFusion 10 to generate an Excel spreadsheet. However, when I use SpreadsheetFormatRow() and pass in the rows to be formatted, it only does about 3 and then abruptly stops. Here is an example...
ColdFusion Code
<cfscript>
rowCount = 1;
headingRows = 4;
// Create instance of new Spreadsheet
excelSheet = SpreadsheetNew("ReportName",false);
// HEADING (IMAGE) ROW FORMAT
formatHeadingRow = StructNew();
formatHeadingRow.fgcolor="blue";
// Add rows to fill the header area (must add as many as we are spanning with the above image)
for (x=0;x<headingRows;x++) {
SpreadsheetAddRow(excelSheet,"TEST,TEST,TEST,TEST,TEST,TEST,TEST,TEST,TEST,TEST,TEST,TEST");
SpreadsheetFormatRow(excelSheet,formatHeadingRow,rowCount);
rowCount++;
}
</cfscript>
<!--- stream it to the browser --->
<cfheader name="Content-Disposition" value="inline; filename=reportName.xls">
<cfcontent type="application/vnd.ms-excel" variable="#SpreadSheetReadBinary(excelSheet)#">
and here is a screenshot of the resulting Excel sheet
Why is the formatting stopping after X number of rows and cells?
If I switch to using XML format with
excelSheet = SpreadsheetNew("ReportName",true);
it works properly. However I'm using a custom palette for my colors so I don't think switching to XLSX format is going to work for me. When I try and then call
palette = excelSheet.getWorkbook().getCustomPalette();
I get an error stating that getCustomPalette() method is undefined.
coldfusion.runtime.java.MethodSelectionException: The getcustompalette method was not found
Can anyone help me figure this out? Thank you!!!
Or even better since it works with the XML format, can anyone show example of how to use a custom palette with the XLSX (xml format)
This is an issue I have seen often when dealing with xls files from CF; they seem to stop applying styles after a certain number of cells. I've been able to work around it by outputting to xlsx instead. (I was able to replicate and "fix" your issue by doing so.)
excelSheet = SpreadsheetNew("ReportName",true);
...
<cfheader name="Content-Disposition" value="inline; filename=reportName.xlsx">
<cfcontent type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
variable="#SpreadSheetReadBinary(excelSheet)#">
Since you are applying the exact same format to all rows, only do it once, not on each row. Using SpreadsheetFormatCellRange after the loop should resolve the issue:
SpreadsheetFormatCellRange(excelSheet
, formatHeadingRow
, startRow
, startCol
, endRow
, endCol );
I suspect the problem somehow relates back to Excel's maximum style limits. Since CF is a black box, it is difficult to know how many styles it actually creates or exactly how they are applied. However, in my experience it is very easy to exceed the style limits without even knowing it. Especially when using the older .xls file format, whose limits are much lower. That is why I suggested using the newer .xlsx format instead.
getCustomPalette() method is undefined.
Correct. It does not exist in XSSF. Is there some reason you need a custom palette instead of just defining your own colors, as mentioned in your other thread?
I searched around for this for awhile, so forgive me if there is an answer already. I am having trouble applying borders to merged cells using CFSpreadsheet. Below is some example code.
<cfscript>
newSS = SpreadsheetNew('Testing'); //Create Spreadsheet
SpreadsheetMergeCells(newSS,1,1,1,9);
SpreadsheetAddRow(newSS,'Underline this Header');
SpreadSheetFormatCell(newSS,{bold=true,alignment='center',bottomborder='thin'},1,1);
Spreadsheetwrite(newSS,expandpath('myTest.xls'),true); //Write File
</cfscript>
What I would expect is the top cell to be underlined all the way across. What I get is the top cell only underlined through column "A" and not underlined after. Is there anyway around this or is this just a limitation of CFSpreadsheet??
Thanks!
According to the POI FAQ's, ie underlying library CF uses to generate spreadsheets, this is currently not supported (emphasis mine):
12. How do I add a border around a merged cell?
Add blank cells around where the cells normally would have been and
set the borders individually for each cell. We will probably enhance
HSSF in the future to make this process easier.
Probably the best you can do for now is to use SpreadsheetFormatCellRange instead of SpreadSheetFormatCell:
SpreadsheetFormatCellRange ( newSS
, {bold=true,alignment='center',bottomborder='thin'}
, 1,1,1,9 );