Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CT_Text.Write throws null exception #180

Closed
luoyigit opened this issue Feb 18, 2019 · 5 comments
Closed

CT_Text.Write throws null exception #180

luoyigit opened this issue Feb 18, 2019 · 5 comments

Comments

@luoyigit
Copy link

luoyigit commented Feb 18, 2019

doc.Write(outFile);
{System.NullReferenceException: Object reference not set to an instance of an object.
at NPOI.OpenXml4Net.Util.XmlHelper.EncodeXml(String xml)
at NPOI.OpenXmlFormats.Wordprocessing.CT_Text.Write(StreamWriter sw, String nodeName)
at NPOI.OpenXmlFormats.Wordprocessing.CT_R.Write(StreamWriter sw, String nodeName)
at NPOI.OpenXmlFormats.Wordprocessing.CT_P.Write(StreamWriter sw, String nodeName)
at NPOI.OpenXmlFormats.Wordprocessing.CT_Tc.Write(StreamWriter sw, String nodeName)
at NPOI.OpenXmlFormats.Wordprocessing.CT_Row.Write(StreamWriter sw, String nodeName)
at NPOI.OpenXmlFormats.Wordprocessing.CT_Tbl.Write(StreamWriter sw, String nodeName)
at NPOI.OpenXmlFormats.Wordprocessing.CT_Body.Write(StreamWriter sw, String nodeName)
at NPOI.OpenXmlFormats.Wordprocessing.CT_Document.Write(StreamWriter sw)
at NPOI.OpenXmlFormats.Wordprocessing.DocumentDocument.Save(Stream stream)
at NPOI.XWPF.UserModel.XWPFDocument.Commit()
at NPOI.POIXMLDocumentPart.OnSave(List`1 alreadySaved)
at NPOI.POIXMLDocument.Write(Stream stream)

@FedePorti
Copy link

I have the same problem. Could you solve it?
My code was working good, but I added a table at the beginning in the word template and now I get this error.

@tonyqus
Copy link
Member

tonyqus commented May 28, 2021

Please upload your word template to help reproduce the issue

@FedePorti
Copy link

FedePorti commented May 28, 2021

Original Good.docx
Modify 1.docx
Modify 2.docx
Here are the files, the original (that worked well) and the others with the modification (I insert a table and I change the header).

And here is how I save it:

Dim out As New FileStream(FileNameSaved, FileMode.Create, FileAccess.Write)
doc.Write(out)
out.Close()
doc.Close()

@FedePorti
Copy link

FedePorti commented May 28, 2021

ModWordPOI.txt

And this are the functions that I create to write in a word document (most of them to write in tables), maybe this can help other people

@FedePorti
Copy link

@tonyqus, I found the error. In my function WriteCell the text was nothing, so when I call SetText(text) did not through an exception but yes when I try to save it, so that was the problem.

I update my function in the document attached.
ModWordPOI.txt

tonyqus added a commit that referenced this issue Jun 25, 2021
If valueField is null do nothing
fix #180
@tonyqus tonyqus closed this as completed Jun 25, 2021
@tonyqus tonyqus added this to the NPOI 2.5.5 milestone Jun 25, 2021
@tonyqus tonyqus changed the title world操作的XWPFDocument对象 write方法发生空引用异常。 CT_Text.Write throws null exception Jun 26, 2021
@tonyqus tonyqus modified the milestones: NPOI 2.5.5, NPOI 2.5.4 Jun 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants