Add padding to row heights in XLSX with Apache POI - apache-poi

I have some code that outputs an excel file using POI and I want to have it so that my Row heights have a bit more space than the automatic heights that get set if I do nothing.
Currently i get a row using sheet.createRow(rowNumber) and then I don't set the height at all, and excel / POI just seems to take care of that.
I now want to add a buffer to the automatically set heights, (say 20px) but I cant see a way to do this, when I add my cells it doesn't seem to actually set the height property of the row automatically, so I can't do row.setHeight(row.getHeight()+20) because getHeight just returns the default height, and so all my Rows end up the same height, instead of the auto height + 20.
Similarly if i set the Default height of the sheet it doesn't bother automatically working out heights for anything that needs to be bigger than the default.
Is there a way to do this?

Actually you're using the right API but as Axel Ritcher pointed out, there is no concept of padding for a cell. The only problem is that 20 is such a tiny value that you can't see any notable difference. You can try something like:
row.setHeight((short)(row.getHeight() * 2));

Related

How to set a static width for a gantt cell

I'm using dhtmlx gantt component to render a Gantt chart and I need each cell in the timeline to have a fixed width, 10px for example, I tried to use the attribute min_column_width and it does make the columns smaller but it's not using the desired width, is there any way to use a static width?
Here is a snippet https://snippet.dhtmlx.com/5/c4362d05c
And I need each one of these cells (the ones of the headers and the ones where the tasks are) to have a fixed width. I appreciate any help or insight on this :) Thanks for reading!
Unfortunately, there is no built-in way to set a fixed timeline cell width. The dev team will try to add that feature, but I cannot promise that.
For now, you need to implement a custom solution.
The timeline cell width depends on several things:
• The gantt.config.min_column_width parameter.
• The displayed date range.
• Gantt container size.
When there are many cells displayed in the timeline so that all of them won't be able to fit the Gantt container size, Gantt uses the min_column_width parameter and adds a scrollbar.
If the cells are able to fit the Gantt container size or even take a smaller size, Gantt stretches them.
So, to have the exact timeline cell size, you need to increase the visible date range:
http://snippet.dhtmlx.com/5/f4f37b79b

Prevent Excel from changing x-axis on a dynamic chart

I wanted to make a dynamic chart that plots out the graph of a standard curve for a bio assay we perform frequently. Often to boost the fit of the curve you may drop one or two data points on either end of the data set. So using vlookups and if statements I have a scheme that performs that data trimming, such that my data always starts in Row 1 and the column length simply shortens.
My table works great, but my xy scatter chart goes bananas on these changes. I have the plot on a log log scale, which looks fine if the full data set is present. I lose the x axis detail when I perform a trim. The x- axis then resets to range of 1 to length of my data set.
How can I prevent this?
UPDATE
I added some information. I know there are VBA ways to do this but I would prefer to keep the spreadsheet as simple as possible. I would think excel should be able to handle this.
So if I have a bad fit I may want to trim the data series either from the beginning or end of the data set. I accomplish that with the spinner buttons to dynamically change the table but the following happens
My formula that updates the columns looks like the following. Its messy.
=IF(ISNA(IF(VLOOKUP(F6,$C$4:$D$11,2,FALSE)+1>8-($B$5-1),"",INDEX(C$4:C$11,VLOOKUP(F6,$C$4:$D$11,2,FALSE)+1))),"",IF(VLOOKUP(F6,$C$4:$D$11,2,FALSE)+1>8-($B$5-1),"",INDEX(C$4:C$11,VLOOKUP(F6,$C$4:$D$11,2,FALSE)+1)))
In the formulas use NA() instead of "". Filling cell with "" does not result in a true empty cell and is the reason why you are experiencing issues with your chart.
Hope that helps.
I may be missing the obvious here, but just hard-code the graph with a range of your choosing. In the sample screenshot, making the graph auto defaults the max range to 100,000. I went in and hard-coded the maximum to 50,000 (circled). Afterwards, the 5th data point is not displayed in the chart. Doesn't matter what the data shows at this point.

Excel - Cells Printing as ##### after Fit all Columns on One Page

I had autosized all of the columns beforehand, but when I fit all columns on one page in the print screen some columns turn into #######. Is there a way to prevent this without manually going in and making those columns bigger? (The ####### does not show up on the actual excel sheet, the number that occupies the cell does)
Thank you for any help.
If it's always the same column, I'd start by seeing if you can reduce the font size a little so that the width of the printed data isn't greater than the size of the column when the fit-to-one-page routine squeezes things together.
If you need an automated solution that will run whenever you get ready to fit-to-one-page and print, that's beyond my skills. Maybe VBA code that adds the column widths, predicts the % they'll be reduced, and checks to see which columns need to have their font shrunk & by how much... not a small project, that.
But if you can live with a manual solution, I'd start by a small reduction in font size. Or see if tweaking the margins helps -- tricks from college to get a "10 page paper"!

Different size items in a VariableSizedWrapGrid

The app I'm working on uses a grouped GridView. Different templates are being used for different items on display and this is causing me an issue with the layout because the VariableSizedWrapGrid sets the row & column sizes based on the first item in each group.
I've tried to use the commonly-suggested solution of PrepareContainerForItemOverride and I'm encountering two problems:
It seems that I can only adjust the height & width around multiples of the column & row spans. That can leave me with quite a bit of wasted space if, say, item #2 needs to have 1.5 x the row height of item #1. I also seem to have to "guess" at what the most appropriate multiple is, which doesn't seem to be appropriate when apps are supposed to scale dynamically.
If I get the multiples too big, the content is horizontally & vertically centred. I've tried changing the alignment from stretch to left in various places but I cannot find which control property to set to get this to work.
Is there a better way of adjusting the item sizes than grid spans? If there isn't, is there a better way for me to lay out my content with variably sized items?
Thanks.
http://winrtxamltoolkit.codeplex.com/ includes WrapPanel which does the job perfectly. It stacks the individual items either horizontally or vertically and wraps onto the next row/column as required.

Is there a way to use logic in Excel to change fonts?

So I've been working with excel to change characters and colors within cells based on where numbers fall. For example when looking at values less than 10 a symbol will appear as red down arrows and values higher than 30 will be create a green up arrow. This is all well and good and I'm using the Wingdings 3 font on the cells along with various rules to change color. The problem is the middle range. I am attempting to have a circle of varying color appear when the cells being looked at contain values greater than 9 and less than 30 (currently it displays as a horizontal double headed arrow). The problem is the Wingdings 3 font does not include any circle symbols and I can't figure out how to use the Conditional Formatting to change the font based on numerical value.
Hopefully there is a fix to this so that I can continue working on this project.
Below is what my spread sheet currently produces:
Just kidding about the image I don't have enough reputation to do that yet.
Alright so the best way to do this (for my problem) was to go into the Conditional Formatting section of Excel and instead of using the IF function by cell just use the icon sets and manage the rules associated with them. I only needed a red and green arrows and circles and with some toying around with the settings a 4 symbol icon set with my chosen shapes did the trick. It ended up being simpler than the IF logic along with rule application I was attempting at the beginning. Just know that there are few symbol choices and no way to add more in the current version of Excel.

Resources