Epplus row height issue - epplus

I have an excel file with over 1000 rows. Each row contains some data and 2 images.
The images are attached as OfficeOpenXml.Drawing.eEditAs.OneCell
After populating the Excel I run this, to set the row height.
int prodTableStart = 3;
int prodTableEnd = 1025;
while (prodTableStart <= prodTableEnd)
{
ws.Row(prodTableStart).Height = 112d; // works, but mega slow
prodTableStart++;
}
I tried to speed up with something like this: ws.Cells["A" + prodTableStart + ":L" + prodTableEnd].Rows but that returns an int?
So how can I set the row height efficient on a selected range of rows?
When I have so many rows, it even never ends. No exception is thrown. The process just takes for ever.
ps. I am using epplus latest nuget (4.1.0) on .Net 4.6.2 in C#

Setting the row height in EPPlus can be really slow. Instead of updating the row height of multiple rows one by one, you can set the row height for all rows very fast like:
workSheet.DefaultRowHeight = 500;
If you don't want to set all row heights you now can set back the row height to the previous default value of these rows one by one. This solution is faster if the rows the height needs to be updated are more than the rows the height not needs to be updated.

To anyone looking for this 4 years later: for some reason, resizing a row that contains an image slows things significantly. For efficiency, calculate and set the rows heights before adding the images. You will likely need to add the rows with all of their text information, with string.Empty cells where the images will go, and then add them after setting heights for the rows.

Related

How to fit column width in macro?

I wrote a macro which copies table from excel to word. In excel all columns have different width. In Word I want to fit my table to one page - margins in Word are 1.5 cm from left and right. Number of rows in my table changes, number of columns is stable (this is 14). How can I set column width to be equal? I wonder if it's possible to set the same column width regardless of the amount of text in headlines. I create swdth variable which I then divide by 14 (all my columns) and I have my table on one page...
This code doesn't work properly. I have all rows in one page, but columns have different width.
Table.Rows.SetHeight RowHeight:=InchesToPoints(0.17), HeightRule:=wdRowHeightExactly
Table.Rows(1).SetHeight RowHeight:=InchesToPoints(0.59), HeightRule:=wdRowHeightExactly
sWdth = InchesToPoints(6.22)
WordTable.PreferredWidthType = wdPreferredWidthPoints
WordTable.PreferredWidth = sWdth
sWdth = sWdth / 14
Giving all columns the same with is as simple as:
Table.Columns.DistributeWidth
but it's not apparent what this has to do with keeping the table on one page.
I've seen similar questions recently. As always...
#1) Turn on the Macro Recorder
#2) Click through the steps you need to perform
#3) Turn off the Macro Recorder
Hit Alt+F11 and you should see all the code you need to do whatever you want to do. Remember, the Macro Recorder is your friend!

Detecting last row and calculating total rows on page

I am currently working with a client that generates their invoices manually in Excel. I have used epplus to generate this file automatically for them.
One of the requirements I have is that each page should have a border around it and start with a header that is about 7 rows long (and each row has different heights based on what I have to put in them). In order to do this, I need to detect when I am at the end of a page so that I can pause my data printing and print out the header, then print out all the data for that page and print the border on the page based on how many rows are on the page.
This was a bit easier when the row heights were static because I could just assume that based on the page settings, that there were a specific amount of rows per page. However, some of the rows on the invoice can have multiple lines which means that WrapText = true. This obviously alters the numbers of rows on the page which throws all my formatting off.
Is there a way to calculate how many rows are on a page and detect when I am on a row where the page ends?
Thanks in advance for any help
To get the row count, and column count, I used the following code:
// get the first worksheet in the workbook
ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets[1];
//Gets the row count
var rowCnt = worksheet.Dimension.End.Row;
//Gets the column count
var colCnt = worksheet.Dimension.End.Column;

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

VB.NET CHART- Display a subset of the total data points

VB 2008
.NET FRAMEWORK 3.5
MSCHART - FASTLINE CHART TYPE
Is it possible to have an MS Chart control contain 20,000 data points, but only show the last 100?
I know that I can select the last 100 from my datatable and use it as a datasource.
Chart1.DataSource = cMs2.dsData.Tables("readings").Select(wFilter, wSort).Take(100)
That's not what I want.
I know that I can populate an array or collection with the last 100 data points and use it as a data source.
Chart1.Series("readings").Points.DataBindXY(colCtr, colReadings)
That's not what I want.
I need to do 1 of 2 things:
Manually add data points and be able to show only the last 100 or last 1000 of them that just came in. This must be done without re-populating the chart. Just show a portion of the complete set of data points.
wSample = wSample + 1
Chart1.Series("readings").Points.AddXY(wSample, wReading)
Chart1.Series("readings").SHOWONLYTHELAST100DATAPOINTSWITHOUTCLEARING
Initialize a chart with a certain number of the total readings with a databind, then manually add new data points one at a time while removing the oldest data point. For example, initialize the chart with 100 data points, then add a new data point, remove the first data point, getting us back to 100. (I'm successfully doing this one, except the chart doesn't behave like I expect. The chart grows, remaining blank/empty where the 'removed' data points were. I do chart.update but it doesn't refresh it.) Note that I am allowed to take more time to initialize the chart (clear/populate), I don't have that time to do it as each new data point comes in.
wSample = wSample + 1
Chart1.Series("readings").Points.AddXY(wSample, wReading)
If Chart1.Series("readings").Points.Count > 100 Then
Chart1.Series("readings").Points.RemoveAt(0)
Chart1.Update()
End If
NOTE: Doing a process that causes me to have to clear and rebind the data to handle the addition of a single data point causes me problems because it takes too long. I'm just looking for the quickest, most efficient way to handle this. Thank you for taking the time to read this...!
You can manually set the Minimum and Maximum values of each axis by modifying the .Minimum and .Maximum values of the axes like
Chart1.ChartAreas(0).AxisX.Minimum = 100 'Example value
Chart1.ChartAreas(0).AxisX.Minimum = 200 'Example value
As discussed in the comments to your question you can either use your method #2 (add datapoint and delete datapoint index 0 and then select the new minimum and maximum X-Value from the series with LinQ:
Chart1.ChartAreas(0).AxisX.Minimum = (From p As DataVisualization.Charting.DataPoint In Chart1.Series(0).Points Select p.XValue).Min
Chart1.ChartAreas(0).AxisX.Maximum = (From p As DataVisualization.Charting.DataPoint In Chart1.Series(0).Points Select p.XValue).Max
or you can, as you have now done, just set the minimum value to a X-value some points before the last point.

SSRS Report Printing Incorrectly

I am trying to figure out why a row keeps on blowing up during printing. Here is an example: http://imgur.com/OQD9VEh #2 is where it is getting extended. As you can see it happens when the data continues on to the next page. It is because of the columns on the right where the values are "Family" and "Mom". If I remove those two columns, the report prints out fine. Once I add them back in, the last row, no matter the row, expands dramatically if it is the leading row on the next page.
Things that I have already tried which have not worked:
- Disabling the option to have the cells increase or decrease in height.
- Tried increasing the height and width of the tablix
- Altered the data type and size to only 6 char for both columns on the left
Any ideas?
Add a column to the right of your outermost column and set its width to very small with no borders and background color(invisible). This may do the trick.
have you try to have the same row height same as the above.
try to set the row "Can Shrink" to false and "Can Grow" to false