ReoGrid Forum

Fast and powerful .NET Spreadsheet Component

You are not logged in.

Announcement

This forum no longer accepts new user registrations, please report your question, problem and feedback to the issue page of ReoGrid on Github. Thanks for your cooperation.

https://github.com/unvell/ReoGrid/issues

#1 2016-06-16 07:21:24

anachbag
Member
Registered: 2016-06-16
Posts: 7

System.NullReferenceException when trying to save worksheet

Hi there,

having a little problem here where I don`t really know how to solve it...
My original problem was/is, that I wanted to print a Worksheet,
but here I get the Exception "System.NotImplementedException - WPF Print is not implemented yet. Try use Windows Form version to print document as XPS file.".
So I tried some work-arounds, like trying to save the Worksheet (SaveRGF), but here I get an Exception too:
"System.NullReferenceException"
   at unvell.ReoGrid.Worksheet.a0.c(Int32 A_0, Int32 A_1, Cell A_2)
   at unvell.ReoGrid.Data.Index4DArray`1.a(Int32 A_0, Int32 A_1, Int32 A_2, Int32 A_3, Boolean A_4, Func`4 A_5)
   at unvell.ReoGrid.Worksheet.SaveRGF(Stream s)

As my application is WPF based, I just can`t easily switch to Windows Forms for it (especially as I can`t use the 2 different references/dll`s in one project, as they are named the same...)

Somebody has a solution for this?
Using latest version 1.3.0

best regards,
Andreas

Offline

#2 2016-06-16 14:53:32

Jing
Moderator
From: jing at reogrid.net
Registered: 2014-06-03
Posts: 615

Re: System.NullReferenceException when trying to save worksheet

Can you save the worksheet as Excel file format? And can you please send the Excel file to me: jing at reogrid.net. I will check for this problem.

Offline

#3 2016-06-16 18:01:37

anachbag
Member
Registered: 2016-06-16
Posts: 7

Re: System.NullReferenceException when trying to save worksheet

Save as Excel doesn`t work (NotSupportedException), and when I try to save it as RGF I'll get the "NullReferenceException"...
I've sent you an export as a html file, hope this helps a bit.
rebuilt now that part with a Windows Forms App, with the same result :-/
So it`s not an WPF issue.

Stepped now through building my sheet, seems like I could already locate the error reason:
I`m having a formula in one cell (lets say "E2"), which uses for calculation a value from a cell some rows below (e.g. "E19").
when I try to save before that formula, everything is working; after setting the formula and trying to save, I get the NullReferenceException...

Offline

#4 2016-06-16 23:27:44

Jing
Moderator
From: jing at reogrid.net
Registered: 2014-06-03
Posts: 615

Re: System.NullReferenceException when trying to save worksheet

My typo, you can save your workbook as Excel file, because I can't use HTML file to test the problem.

Last edited by Jing (2016-06-16 23:30:30)

Offline

#5 2016-06-17 06:28:01

anachbag
Member
Registered: 2016-06-16
Posts: 7

Re: System.NullReferenceException when trying to save worksheet

saving doesn`t work - that`s my problem!
but I`m even one step closer what is causing the error: seems like the exception only occurs when (or after) I applied a CellDataFormat (CellDataFormatFlag.Number) to a cell.
disabled now all formatting and now I could save the file.
just passed it to you per mail

Offline

#6 2016-06-17 06:37:27

anachbag
Member
Registered: 2016-06-16
Posts: 7

Re: System.NullReferenceException when trying to save worksheet

here is the problem: (short version)

this.reoGridControl1.CurrentWorksheet.Cells[0, 0].DataFormat = CellDataFormatFlag.Number;
this.reoGridControl1.CurrentWorksheet.Save("file.rgf");

Offline

#7 2016-06-29 10:53:29

anachbag
Member
Registered: 2016-06-16
Posts: 7

Re: System.NullReferenceException when trying to save worksheet

same problem occours also when I try to copy a worksheet (grid.CopyWorksheet)...
but a sheet without formatting is a bit useless so to say :-/
any suggestions? is it working in pro version?

Offline

#8 2016-06-30 00:11:40

Jing
Moderator
From: jing at reogrid.net
Registered: 2014-06-03
Posts: 615

Re: System.NullReferenceException when trying to save worksheet

Try set a number format argument, looks like a bug where didn't check the argument is null in current version.

  sheet.Cells[0, 0].DataFormat = CellDataFormatFlag.Number;
  sheet.Cells[0, 0].DataFormatArgs = NumberDataFormatter.TwoDecimalDigitsArgument;

Last edited by Jing (2016-06-30 00:12:17)

Offline

#9 2016-06-30 06:18:07

anachbag
Member
Registered: 2016-06-16
Posts: 7

Re: System.NullReferenceException when trying to save worksheet

thank you very much, this seems like it was the problem, can now save the worksheet!
just a quick sidenote: when using a DataFormat = CellDataFormatFlag.DateTime - I get again the same Exception...

having another small question:
tried to make a colored border, but whatever color I set, the border (BorderLineStyle.BoldSolid) keeps black?

Offline

#10 2016-06-30 07:23:39

Jing
Moderator
From: jing at reogrid.net
Registered: 2014-06-03
Posts: 615

Re: System.NullReferenceException when trying to save worksheet

You may need to set datatime format argument, format flag with argument are paired to be necessary for cell data formatting. see https://reogrid.net/document/data-format/

Could you please show me your code to set border styles? thanks.

Offline

#11 2016-06-30 08:40:04

anachbag
Member
Registered: 2016-06-16
Posts: 7

Re: System.NullReferenceException when trying to save worksheet

ok, I'll try it with setting a DateTimeFormat, in the meanwhile I changed the cell type to text ;-)

here`s the part with the border:

RangeBorderStyle rbsColor = new RangeBorderStyle() { Color = unvell.ReoGrid.Graphics.SolidColor.Orange, Style = BorderLineStyle.BoldSolid };
ws.SetRangeBorders(1, 1, ws.Cells[1, 1].GetRowspan(), ws.Cells[1, 1].GetColspan(), BorderPositions.Top | BorderPositions.Left | BorderPositions.Right, rbsColor);

ws is my current worksheet.
the border is drawn, but with black color instead of the specified orange

Offline

#12 2016-06-30 09:37:58

Jing
Moderator
From: jing at reogrid.net
Registered: 2014-06-03
Posts: 615

Re: System.NullReferenceException when trying to save worksheet

Can't get problem by using the code you provided. I think there should be something else that affects the result of your worksheet.

My result with your code: (WPF)
441.png

If possible please send your project or an entire dummy project that causes the problem happening to my mailbox: jing at reogrid.net. Thanks.

Last edited by Jing (2016-06-30 09:39:57)

Offline

Board footer

Powered by FluxBB