Setting Page Breaks on Empty Rows


#1

Dear Support,

I have an Excel Report that contains blocks of data separated by an empty row. I wrote logic to traverse through every row and check the first cell to see if it’s empty. The logic works fine, however I’m not able to create a PAGE BREAK on the empty cell. What am I doing wrong?

The following is the code segment:

for(int i = 0; i <= designer.Excel.Worksheets[0].Cells.MaxRow; i++) {
if (designer.Excel.Worksheets[0].Cells[i,0].Value.ToString() == “”)
designer.Excel.Worksheets[0].HPageBreaks.Add(i,0);
}


Thanks,
Tom Raic


#2

I addition… I’m getting a Null Object Reference Exception when I call the Page Break function.


#3

Actually the error is… “Object reference not set to an instance of an object.”


#4

Which version are you using? That's a bug in earlier version. Please download and try v3.3.3 at www.aspose.com/downloads .


#5

I am running version 3.3.0. Are you sure I’m not missing anything from my code? It does not recognize the HPageBreaks collection. Why does it work for others?

for(int i = 0; i <= designer.Excel.Worksheets[0].Cells.MaxRow; i++) {
try {
if (designer.Excel.Worksheets[0].Cells[i,0].Value.ToString() == “”)
{
designer.Excel.Worksheets[0].HPageBreaks.Add(i,0);
}
}
catch (Exception ex) {
throw ex;
}
}


#6

You code is fine. I have tested it and don’t find any problem. Please try v3.3.3 at www.aspose.com/downloads.


#7

Can you send me the Excel file that you tested my code with. I have 3.3.0 already installed. You’re not giving me productive assistance. If you can’t fix this today, I’ll be forced to refund the product, and probably use another product, like SyncFusion. You told me to download the same installer twice that I have on my box already. THAT"S NOT HELPFUL AT ALL!

Angry Customer,
Garvan Interactive, LLC.


#8

Can you send me the exact source code and Excel file that you used to test this? If it really works, send me your project file!


#9

Sorry for the frustrations… I’m just trying to make one of my clients happy.


#10

I FIXED IT MYSELF. The code segment i gave you DOES NOT WORK! So if you claimed you tested it, you didn’t. The Value of a Cell needs to test against a NULL value. If you see my code, you will get an error when you use the ToString function. I know you guy’s are busy over there, but if you’re goign to service a customer, do it right. You shouldn’t tell your customers that their code is right, and then lie to them about testing it yourself.

Not cool!


#11

Sorry for any inconvience.

I did test your code. The following is my whole program and the attached file is my template file.

ExcelDesigner designer = new ExcelDesigner();

designer.Open("d:\\book1.xls");

for(int i = 0; i <= designer.Excel.Worksheets[0].Cells.MaxRow; i++)
{
try
{
if (designer.Excel.Worksheets[0].Cells[i,0].Value.ToString() == "")
{
designer.Excel.Worksheets[0].HPageBreaks.Add(i,0);
}
}
catch (Exception ex)
{
throw ex;
}
}


designer.Save("d:\\result.xls");


The above code works fine and I did find a similar problem in earlier version. So I had thought it's fixed in the new version and didn't make further investigation.

Anyway, I apologize for my carelessness. We will shape our testing and support process to serve our customers better.