8 Replies Latest reply: May 30, 2010 4:45 AM by EJP RSS

    Making a paragraph bold in a .doc file.

    807580
      From within a Java program a .doc file is written. The file contains some \r\n characters to skip lines. It contains some \f for a page break. Are the any control character that can be written to cause a paragraph to be bold or be centered when the file is opened by MS Word.

      Thank you.
        • 1. Re: Making a paragraph bold in a .doc file.
          gimbal2
          are you sure it is an actual doc file, and not for example an RTF file?
          • 2. Re: Making a paragraph bold in a .doc file.
            807580
            The Java program is writing the file and it puts a .doc as an extension.
            • 3. Re: Making a paragraph bold in a .doc file.
              jschellSomeoneStoleMyAlias
              zscipio wrote:
              From within a Java program a .doc file is written. The file contains some \r\n characters to skip lines. It contains some \f for a page break. Are the any control character that can be written to cause a paragraph to be bold or be centered when the file is opened by MS Word.
              Word docs have a binary format. The fact that there is text in them doesn't change that.

              There are two possibilities
              1. You are using a library that deals with that binary format.
              2. Someone hacked together a pseudo template which has the correct form and then just inserted text into the correct place.

              If the first then you need to learn the library.
              If the second then you need to learn how the binary format works, create a new template and then use it. And in looking at Word files from Office 2007 and the previous version I doubt this solution is viable if you want to do anything except stick text in there.

              At least at one time you could google for Word file formats.
              • 4. Re: Making a paragraph bold in a .doc file.
                807580
                Judging from the replies I did a poor job of posing the question. Let me try again.

                I wrote a Java program that writes data to a file that MS Word is going to read. So the name of the file is text.doc.

                Whenever a new paragraph is needed \r\n is written to text.doc.
                Whenever a new page is needed \f is written to text.doc.

                Are the any controls that can be written before a paragraph to cause it to be bold?
                Are the any controls that can be written before a paragraph to cause it to be center justified?
                Are the any controls that can be written before a paragraph to change its font size?

                After text.doc is written it is closed & opened by MS Word.

                Thank you for your help.
                • 5. Re: Making a paragraph bold in a .doc file.
                  807580
                  It looks like you're trying to use RTF and saving as a DOC? I think you could use \b. You could look at POI though: http://poi.apache.org/ or check http://en.wikipedia.org/wiki/Rich_Text_Format
                  • 6. Re: Making a paragraph bold in a .doc file.
                    jschellSomeoneStoleMyAlias
                    zscipio wrote:
                    Judging from the replies I did a poor job of posing the question. Let me try again.

                    I wrote a Java program that writes data to a file that MS Word is going to read. So the name of the file is text.doc.
                    That doesn't help much. As I already said the Word "doc" format is a binary format.
                    You understand what that means right?
                    Whenever a new paragraph is needed \r\n is written to text.doc.
                    Whenever a new page is needed \f is written to text.doc.
                    Which suggests that you got lucky.
                    Are the any controls that can be written before a paragraph to cause it to be bold?
                    Are the any controls that can be written before a paragraph to cause it to be center justified?
                    Are the any controls that can be written before a paragraph to change its font size?
                    As I noted you can get the file format specification. It didn't even take me very long to find it.

                    [http://www.microsoft.com/interop/docs/officebinaryformats.mspx]


                    From that I find the following....

                    +"That chp has chp.istd=istdNormalChar. chp.hps=20, chp.lid=0x0400, and chp.ftc=4. Word then compares fBold, fItalic, fStrike, fOutline, fShadow, fSmallCaps, fCaps, ftc, hps, hpsPos..."+

                    My interpretation of that without doing much more than just reading that would suggest that bold is represented by a single bit in some structure.
                    • 7. Re: Making a paragraph bold in a .doc file.
                      DrClap
                      So you are writing some format which is understood by MS Word, but that's all you know about it. And you have a question about that format.

                      That isn't a question about Java programming in the least. If you don't know what format you are writing, you should find out so that you know where to ask this question.
                      • 8. Re: Making a paragraph bold in a .doc file.
                        EJP
                        Not a Java question. Locking this thread.