I've some problems with Apache POI, some help would be nice!!
I would like to remove the colors in a subpart of an Excel sheet.
To do so, the first thing I tried is to render the cells I want to clean (let say the one of the first row only) and to set their color to white:
cell.getCellStyle().setFillForegroundColor(IndexedColors.WHITE.index);
But if i do that, the color of some cells that are not rendered (let say the one of the second row) are also changed to white cells. It's strange, because the cells that are changed do not have the same foreground color, so I thought they would have different styles ...
Therefore, I've tried another way:
CellStyle style = workbook.createCellStyle();
style.setFillForegroundColor(IndexedColors.WHITE.index);
cell.setCellStyle(style);
The idea, is to avoid changing a style that may be common to different cells in the Excel sheet. Actually, it solves the color problem, but if I do that, I loose the different styles in the Excel sheet, while I only want to remove some colors...
I'm using a generic Workbook, and I'm reading a xlsx (same problem with a xls)
Do you know how to do it ?
Thx a lot,
regards,
If you want to remove the colors, then probably it makes sense to change the fill pattern to NO_FILL rather than setting the color to white as follows:
style.setFillPattern(CellStyle.NO_FILL)
Back to your main question, you've got 2 options of dealing with the cell style amendment:
By modifying style viaCellUtil.setCellStyleProperty method
CellUtil.setCellStyleProperty(cell, workbook, CellUtil.FILL_PATTERN, CellStyle.NO_FILL)
By cloning styles from the existing style and modifying the property
The example code shown below:
CellStyle oldStyle = cell.getCellStyle();
CellStyle newStyle = workbook.createCellStyle();
newStyle.cloneStyleFrom(oldStyle);
newStyle.setFillPattern(CellStyle.NO_FILL);
cell.setCellStyle(newStyle);
However in the 2nd case you're going to create a new cell style for every cell and you might probably consider reusing some of the already updated cell styles and implementing some kind of caching (as otherwise it might lead to performance issues and reaching allowed styles limit).
Related
This is my first post on here so go easy.
After using paste linked picture with a conditionally formatted cell, I feel that it doesn't do what I need. Therefore I am trying to format border colours based on cell values but I don't believe I can do this without using VBA, which I have no clue how to use. I want to apply the same conditional formatting rules in the screenshot to the shape border if possible.
Can someone help me out please?
Worksheet screenshot
I don't think its possible (without VBS) to change the thickness of the borders.
But changing the style is possible by editing the rule > click on format > click on border tab and edit your preferred border style.
Hope this is what you meant (Only in german unfortunately)
I think the image attached describes better than I can in words the functionality I am trying to locate within excel.
Is there a way to auto group based on the contents within the columns as shown? This is achievable for the example shown, but when there are up to say 30 Groups and many sub group types, I am wondering whether excel can auto-detect and work its way through the list, grouping as shown as it goes.
You can get a similar result using conditional formatting. select the whole table and create a new conditional format rule and choose formula and enter =A1=A2 set the format font to white (I've used very light grey to show that the data is still there)
To get the borders, do the same again and this time enter the formula =A1<>A2 and make the top border black.
It's not exactly the same as yours but it's close.
I have a custom cell layout, inheriting from MvxTableViewCell. One of the cell's contained views is a UILabel that supports text wrapping. The wrapping will mean the cells can be of different heights as that is driven by how much text is in each data item. The custom table cell is defined without any Storyboard or NIB. It is laid out in code and uses AutoLayout.
I am finding that the cells are being reused and the heights are staying the same as they were when they were previously used.
When the data source is updated and new items are in the table the previously taller cells are reused for cells that don't need that extra height. Do I need to create a custom MvxTableViewSource that has specific reuse logic? How would I even ensure that extra height rows were not reused?
I am hoping this is not a Monotouch and MVVMCross specific issue but just in case, this is how I am using the UITableView
this.searchResultsTable = new UITableView();
this.searchResultsTable.AccessibilityIdentifier = "SearchView_SearchResultsTable";
this.searchResultsTable.TranslatesAutoresizingMaskIntoConstraints = false;
this.searchResultsTable.RowHeight = UITableView.AutomaticDimension;
this.searchResultsTable.EstimatedRowHeight = 44.0f;
this.searchResultsTable.AllowsMultipleSelectionDuringEditing = true;
this.searchResultsTable.TableFooterView = new UIView();
The Table Cells display correctly on first use of the View but subsequent uses cause issues as does scrolling.
For example here is a screen shot of mixed height working followed by the same list after the taller row has been scrolled off the screen then back on. The red boxes show how box the cell should be (FWIW this is test data not real people's data)
Another example, here the table is again displayed correctly then loaded again with the same data yet the second load has the cell height incorrect
I broke my two issues into two questions however there is a solution for both this one and the other issue with this SO answer, UILabel not wrapping in UITableView until device rotate (iOS8)
I'm interested in making an Excel cell formatting macro that allows me to scroll through different options (different font/cell colors, different border types, etc.). I know that I could accomplish this by checking conditions -- if I'm changing font colors, then I can just "scroll" by using conditional logic (if color1, then change to color2; if color2, then change to color 3; etc.). I was wondering if there might be a more elegant way to accomplish this -- specifically, is there a way to store custom attributes for cells in VBA?
For example, if I set cell B3 to a certain border style (thin line for top,left,right but double line for bottom), is there a way to create and set a VBA attribute of Cell.CustomBorderStyle = 1? Otherwise, I believe I would have to build logic into my macro for the precise formatting (if top,left,right = thin and bottom = double then change to second style, etc.). I'm not sure if creating a custom class in VBA would allow me to do this, or if there's any way at all to do this.
Please let me know if my question is unclear -- thanks!
if you only want the cell attribute to be available within this VBA session then I would use a collection or dictionary with a key of the cell address (Sheet_Row_Column) to store the attribute(s).
If you want to persist this information within an Excel workbook then it would probably be best done using custom xml.
I asked this question on the LiveCode email list. No response, so I figure it must not be possible. I know about editing the template graphic that enables alternating row colors. That doesn't help me.
This lesson is the closest to what I have found, but it only sets the overlay color to empty cells. It also had an unwanted affect, where any data that was present in the grid no longer shows up.
http://lessons.runrev.com/s/lessons/m/datagrid/l/7327-how-do-i-override-the-default-behavior-for-rendering-data-to-a-cell
As a little experiment, since the data became invisible (note that I'm on WinXP), I tried placing an opaque graphic over the column I wish to colorize. I set the ink of the graphic to AddMax or AddOver, and it looked nice, but the text in the cells disappeared. Then I tried setting the ink to AddMin, and it still looks good, but the test shows through!!!!
So, I think this will work fine visually, but how can I pass a double-click through this graphic to the cell underneath (to allow cell editing only within this column)?
Yes, you can do this.
This suggestion comes from Trevor DeVore at http://www.bluemangolearning.com/
Create a custom column template using the property inspector. From there you can edit the behavior of the column to colorize the background color of the field for that column or just edit the field in the template group to change the color.
The background color will only show up in rows that have data, however.