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

NPOI - Missing shape in word #769

Closed
DanMerillas opened this issue Mar 2, 2022 · 10 comments
Closed

NPOI - Missing shape in word #769

DanMerillas opened this issue Mar 2, 2022 · 10 comments

Comments

@DanMerillas
Copy link

DanMerillas commented Mar 2, 2022

Hi, i have a simple project that read a word file that contains one text and a shape in the body, when i create other word file with read data a lose the shape. Can someone help me?

The resulting file has a weight less than the original...

I use:

.net Framework 4.6
NPOI 2.5.5

using NPOI.XWPF.UserModel;
using System;
using System.IO;

namespace EditWord
{
    class Program
    {
        static void Main(string[] args)
        {

           
            try
            {
                FileStream f = new FileStream(@"c:\excel\test.docx", FileMode.Open, FileAccess.Read);
                XWPFDocument doc = new XWPFDocument(f);

                FileStream fs = new FileStream(@"c:\excel\test2.docx", FileMode.Create, FileAccess.Write);

                doc.Write(fs);
                fs.Close();
            }
            catch (Exception e)
            {

            }

        }
    }
}

Thank you!!!

@tonyqus
Copy link
Member

tonyqus commented Mar 2, 2022

Can you upload the original word file?

@DanMerillas
Copy link
Author

test.docx
test2.docx

Test.docx is de source word and Test2.docx the result file. Thank you!!!!!

@DanMerillas
Copy link
Author

I do not understand why you say that?

@tonyqus
Copy link
Member

tonyqus commented Mar 3, 2022

Sorry, looks I mixed your Word with a Chinese Word file. hahah.

Btw, where are you from?

@DanMerillas
Copy link
Author

I am from Spain, I have achieved it with openxml but I like this library better. Is it a programming error or some kind of bug or limitation? I guess you are from China...

@tonyqus
Copy link
Member

tonyqus commented Mar 3, 2022

I believe this should be a bug. Openxml SDK is not bad but it's for very senior guy who knows OpenXML very well.

Maybe you can join us via NPOI telegram group: https://t.me/npoidevs

@tonyqus tonyqus added the bug label Mar 3, 2022
@tonyqus tonyqus modified the milestones: NPOI 2.5.7, NPOI 2.5.6 Mar 3, 2022
@DanMerillas
Copy link
Author

If it was difficult for me and I have been developing for 15 years, that's why I liked NPOI, should I ask this in the Telegram group?

@tonyqus
Copy link
Member

tonyqus commented Mar 3, 2022

OK. I know what's going on. This shape is inside mc:AlternativeContent, which is not handled by current OpenXML parser.

      <w:r>
        <w:rPr>
          <w:noProof/>
        </w:rPr>
        <mc:AlternateContent>
          <mc:Choice Requires="wps">
            <w:drawing>
              <wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" relativeHeight="251659264" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="1" wp14:anchorId="0041AD43" wp14:editId="6B9C61AE">
                <wp:simplePos x="0" y="0"/>
                <wp:positionH relativeFrom="column">
                  <wp:posOffset>548640</wp:posOffset>
                </wp:positionH>
                <wp:positionV relativeFrom="paragraph">
                  <wp:posOffset>205740</wp:posOffset>
                </wp:positionV>
                <wp:extent cx="3667125" cy="1752600"/>
                <wp:effectExtent l="0" t="0" r="28575" b="19050"/>
                <wp:wrapNone/>
                <wp:docPr id="1" name="Rectángulo: esquinas redondeadas 1"/>
                <wp:cNvGraphicFramePr/>
                <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                  <a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
                    <wps:wsp>
                      <wps:cNvSpPr/>
                      <wps:spPr>
                        <a:xfrm>
                          <a:off x="0" y="0"/>
                          <a:ext cx="3667125" cy="1752600"/>
                        </a:xfrm>
                        <a:prstGeom prst="roundRect">
                          <a:avLst/>
                        </a:prstGeom>
                      </wps:spPr>
                      <wps:style>
                        <a:lnRef idx="2">
                          <a:schemeClr val="accent1">
                            <a:shade val="50000"/>
                          </a:schemeClr>
                        </a:lnRef>
                        <a:fillRef idx="1">
                          <a:schemeClr val="accent1"/>
                        </a:fillRef>
                        <a:effectRef idx="0">
                          <a:schemeClr val="accent1"/>
                        </a:effectRef>
                        <a:fontRef idx="minor">
                          <a:schemeClr val="lt1"/>
                        </a:fontRef>
                      </wps:style>
                      <wps:bodyPr rot="0" spcFirstLastPara="0" vertOverflow="overflow" horzOverflow="overflow" vert="horz" wrap="square" lIns="91440" tIns="45720" rIns="91440" bIns="45720" numCol="1" spcCol="0" rtlCol="0" fromWordArt="0" anchor="ctr" anchorCtr="0" forceAA="0" compatLnSpc="1">
                        <a:prstTxWarp prst="textNoShape">
                          <a:avLst/>
                        </a:prstTxWarp>
                        <a:noAutofit/>
                      </wps:bodyPr>
                    </wps:wsp>
                  </a:graphicData>
                </a:graphic>
              </wp:anchor>
            </w:drawing>
          </mc:Choice>
          <mc:Fallback>
            <w:pict>
              <v:roundrect w14:anchorId="1312E3C4" id="Rectángulo: esquinas redondeadas 1" o:spid="_x0000_s1026" style="position:absolute;margin-left:43.2pt;margin-top:16.2pt;width:288.75pt;height:138pt;z-index:251659264;visibility:visible;mso-wrap-style:square;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal:absolute;mso-position-horizontal-relative:text;mso-position-vertical:absolute;mso-position-vertical-relative:text;v-text-anchor:middle" arcsize="10923f" o:gfxdata="UEsDBBQABgAIAAAAIQC2gziS/gAAAOEBAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbJSRQU7DMBBF&#xA;90jcwfIWJU67QAgl6YK0S0CoHGBkTxKLZGx5TGhvj5O2G0SRWNoz/78nu9wcxkFMGNg6quQqL6RA&#xA;0s5Y6ir5vt9lD1JwBDIwOMJKHpHlpr69KfdHjyxSmriSfYz+USnWPY7AufNIadK6MEJMx9ApD/oD&#xA;OlTrorhX2lFEilmcO2RdNtjC5xDF9pCuTyYBB5bi6bQ4syoJ3g9WQ0ymaiLzg5KdCXlKLjvcW893&#xA;SUOqXwnz5DrgnHtJTxOsQfEKIT7DmDSUCaxw7Rqn8787ZsmRM9e2VmPeBN4uqYvTtW7jvijg9N/y&#xA;JsXecLq0q+WD6m8AAAD//wMAUEsDBBQABgAIAAAAIQA4/SH/1gAAAJQBAAALAA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dknE7PJmTga8/qtcdu2iugz1TQY+Bk2sb4YA5bjdC+0CQvY1VyCSupdsllwINxFfqxpbdA&#xA;quUyhdEMORFu7ZOTETyyGrX0vHsR6AbVBRLsHRxGSczf6K6PjZkWlpsAukmiPPI68E3zl4QzvBVx&#xA;wF/bKer4oi3+AAAA//8DAFBLAwQUAAYACAAAACEAIEUg7N0AAAAJAQAADwAAAGRycy9kb3ducmV2&#xA;LnhtbEyPMU/DMBCFdyT+g3VIbNShKVFI41SFqhMTgaWbEx9xSmxHttuaf88x0el0957efa/eJDOx&#xA;M/owOivgcZEBQ9s7NdpBwOfH/qEEFqK0Sk7OooAfDLBpbm9qWSl3se94buPAKMSGSgrQMc4V56HX&#xA;aGRYuBktaV/OGxlp9QNXXl4o3Ex8mWUFN3K09EHLGV819t/tyQgwKk+7o9wecF+2L4en9LbzuhPi&#xA;/i5t18Aipvhvhj98QoeGmDp3siqwSUBZrMgpIF/SJL0o8mdgHR2ycgW8qfl1g+YXAAD//wMAUEsB&#xA;Ai0AFAAGAAgAAAAhALaDOJL+AAAA4QEAABMAAAAAAAAAAAAAAAAAAAAAAFtDb250ZW50X1R5cGVz&#xA;XS54bWxQSwECLQAUAAYACAAAACEAOP0h/9YAAACUAQAACwAAAAAAAAAAAAAAAAAvAQAAX3JlbHMv&#xA;LnJlbHNQSwECLQAUAAYACAAAACEAuv4z5GMCAAAZBQAADgAAAAAAAAAAAAAAAAAuAgAAZHJzL2Uy&#xA;b0RvYy54bWxQSwECLQAUAAYACAAAACEAIEUg7N0AAAAJAQAADwAAAAAAAAAAAAAAAAC9BAAAZHJz&#xA;L2Rvd25yZXYueG1sUEsFBgAAAAAEAAQA8wAAAMcFAAAAAA==&#xA;" fillcolor="#4472c4 [3204]" strokecolor="#1f3763 [1604]" strokeweight="1pt">
                <v:stroke joinstyle="miter"/>
              </v:roundrect>
            </w:pict>
          </mc:Fallback>
        </mc:AlternateContent>
      </w:r>

@tonyqus tonyqus added the docx label Mar 3, 2022
@DanMerillas
Copy link
Author

Great! nice job! I will look forward to the next version of NPOI

@tonyqus tonyqus closed this as completed in 408ec5a Mar 6, 2022
@tonyqus tonyqus modified the milestones: NPOI 2.6.0, NPOI 2.5.6 Apr 25, 2022
tonyqus added a commit that referenced this issue Apr 25, 2022
@tonyqus
Copy link
Member

tonyqus commented Apr 27, 2022

NPOI 2.5.6 is released, which contains this fix.

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

2 participants