Print on a variable height paper using vb.net - vb.net

I want to print bill on a roll paper using vb.net.
The requirements are as follows:
The width of the page is 300 pixels or 3 inches.
The height of the page is variable, depending on the number of the rows in the datagrid.
The page header will have an image.
The names of the items could be long, so they should not be chopped, rather print on the next line.
How should I go about it?

Get your Image height and xRows (dgv.rows.count) * Rowheight
So you have an Dynamic height.
Additional you could count string lengtht of your long Values and add for longer datarows the addidtional height
But that is just my idea.
Im sure there are better solutions

Related

valign images in xlsxwriter cell

Is there any hack for v-aligning images in a cell
I am trying to create a dashboard,those traffic lights are images.
Since once of the columns is a text-wrap and the height of those rows
are dynamic, I have no way of knowing the row height to calculate the y_offset for those images
Does anyone have a recommendation on how I can handle this? Is there a way of getting the row_height after sheet.write and text_wrap format is applied?
Is there a way of getting the row_height after sheet.write and text_wrap format is applied?
Probably not without access to Windows APIs for calculating bounding boxes for strings.
You could probably make some working estimates based on the length of your string. Each new line in text wrap is equal to 15 character units or 20 pixels.
Since once of the columns is a text-wrap and the height of those rows are dynamic, I have no way of knowing the row height to calculate the y_offset for those images
This is the main problem. In order to specify the image position exactly you will need to specify explicit row heights so that XlsxWriter can calculate where the image will go based on the size of the cell. In order words you will have to avoid the automatic row height that Excel gives you when wrapping text.
Once the row height is fixed you can position images exactly where you want them using the 'x_offset' and 'y_offset' options.
Note, you can also use conditional formatting to create traffic lights based on cell values. See Sheet9/Example 9 of this code from the XlsxWriter docs and image below. These can be centered automatically even with with text wrapping.

Excel cell default measure unit

What is the default measurement unit of Excel cell size? Is it Point or Pixel or Millimeter ?
By default, excel cell Row height is 15, what is the meaning of this value? Is it 15 Pixels or 15 Points
By default, excel cell Column Width is 8.43, what is the meaning of this value? Is it 8.43 Pixels or 8.43 Points
If both row and column units are same, then Row height should be smaller than to column width. But the measurement is reverse, row height shows bigger number than column width. In Cell appearance also, row is small than column width.
I need to create box with Height 90 mm (millimeter) and Width 195 mm (millimeter). Please let me know what are values to be put in Row and Column textboxes.
Thanks in advance.
The default units for column and row are indeed different when accessed through the GUI.
The displayed column width in the GUI refers to the Range.ColumnWidth property, where One unit of column width is equal to the width of one character in the Normal style. For proportional fonts, the width of the character 0 (zero) is used (source). This means as you change the worksheet style, your column width may change too.
The height, however, displays a normal height in points.
In VBA, you can both get both this font-related unit, and the normal point unit for the width. For the height, you can only get the value in points:
Debug.Print Range("A1").ColumnWidth '8.43 characters wide by default
Debug.Print Range("A1").Width '48 points wide by default
Debug.Print Range("A1").Height '12.75 points high by default
Of course, you can calculate a conversion factor between character width and points: Range("A1").Width / Range("A1").ColumnWidth = 5.69 when using Arial, 10 pt. This means that if you want to have a size of 195mm by 90mm, you need to enter 97.0777 as column width, and 255.118 as column height if you're using Arial, 10 pt as normal style.
As per the Microsoft documentation....
You can specify a row height of 0 (zero) to 409. This value represents the height measurement in points (1 point equals approximately 1/72 inch or 0.035 cm). The default row height is 12.75 points (approximately 1/6 inch or 0.4 cm). If a row has a height of 0 (zero), the row is hidden.
Read it more here.
Please throw this link: Microsoft reference
You can change and define this unit manually where pointed in above link:
On the File tab, click Options, click the Advanced category, and under Display, select an option from the Ruler Units list.
So please visit Here Microsoft reference that exactly explain
what you asked.
Above you asked are the pixel width retranslated into character units (based on the Normal font) for display.

I'm getting strange numbers when using the VBA Height function

I am trying to use the Height function in VBA but I am getting strange numbers. Instead of returning the height of a range, it is returning the height of a range multiplied by 15. For example, the following simple function :
Function h(c1 As Range) As Double
h = c1.Height
End Function
would give a value of 15 if c1 was a single cell, would give 30 if c1 was two cells high, and so on. I should clarify that I am using this as part of a larger function, but it is this issue that is causing the problem. I wanted to make a function as simple as possible to see if the problem remained, and it has. I really don't understand why this is happening, I have used the height function before with no problem. Any advice would be greatly appreciated,
Thanks
You are misunderstanding what the height property is. The height is its height in points...
From here..https://msdn.microsoft.com/en-us/library/office/aa215509%28v=office.11%29.aspx?f=255&MSPPError=-2147217396
Returns the height of all the rows in the range specified, measured in points. Returns Null if the rows in the specified range aren't all the same height. Read/write Variant.
Remarks
You can use the Height property to return the total height of a range of cells.
Differences between RowHeight and Height include the following:
Height is read-only.
If you return the RowHeight property of several rows, you will either get the row height of each of the rows (if all the rows are the same height) or Null (if they're different heights). If you return the Height property of several rows, you will get the total height of all the rows.
Example
This example doubles the height of row one on Sheet1.
With Worksheets("Sheet1").Rows(1)
.RowHeight = .RowHeight * 2
End With

UITableView height of a section

I have a UITableView that has 3 sections. My individual cells vary in height (collapse-expand).
I need a way to figure out the height of each individual section, i.e. the sum of cell heights in each section. Preferably without calculating everything the tableView already has done each time I need it.
I there a way to deduce or access such a value?
Did you look at -rectForSection: (and possibly also -rectForFooterInSection:)?
There is no easy way to calculate the value, however there is a way. If your cells have a fixed height it's just the many rows multiplied by their fixed height for each section.
If you have varying height in the cells too, I'd go for an array which holds the total height for each section, just calculate it once and keep it cached there. If the section is collapsed you just need the section header height else it's the value in the array.

dojox.charting: how to align the plotArea of 2 charts, one above another?

I'm trying to layout 2 linked charts, one above the other, similar to what you might see on the Google Finance page.
I can render both charts just fine, but getting the plotAreas to line up exactly is a bit of a mystery. The chart.plotArea.width of each chart seems to depend on the width of my Y axis labels. Thus the 2 charts are not the same width and have different values for chart.getCoord().l.
Right now, I'm using an offset which is manually calculated, but there must be a better way.
this.chart.render(); // top chart, getCoords().w=800
// manually set margins for lower chart to match
this.chartVol.margins.l = this.chart.offsets.l - 59 + 10;
this.chartVol.margins.r = this.chart.offsets.r - 31 + 10;
// render bottom chart
this.chartVol.render(); // bottom chart same width, getCoords().w=800
There are two simple ways to do it:
Use maxLabelSize and labelFunc. The former is the maximal label's size in pixels. The latter is a function, which takes a number, and returns a corresponding string label.
Use labels, which is an array of {value, text} objects, and include one long dummy string of desired size at the end with some bogus value.
I don't recall how to do it without custom labels, so if you feel like it is really needed, please submit an enhancement ticket.