Android Question create .DOC file

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Don, any other lib? Just old simple Word .doc version creator ? RTF? Or ODT?
 
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
I have had some success accessing this library using JavaObject

Copy srw.jar to your library folder

B4X:
#AdditionalJar : srw

And then

B4X:
    Dim Font As JavaObject
    Font.InitializeNewInstance("com.itseasy.rtf.text.Font",Array("FAMILY_ROMAN","TIMES_NEW_ROMAN"))


  
    Dim TextPart As JavaObject
    TextPart.InitializeNewInstance("com.itseasy.rtf.text.TextPart",Array("Your centerd text" ))

  
    Dim Paragraph As JavaObject
    Paragraph.InitializeNewInstance("com.itseasy.rtf.text.Paragraph",Array(28, 0, 34,Font.GetField("TIMES_NEW_ROMAN"),TextPart))
    Paragraph.RunMethod("setAlignment",Array(Paragraph.GetField("ALIGN_CENTER")))
  
  
    Dim PageSize As JavaObject
    PageSize.InitializeStatic("com.itseasy.rtf.text.PageSize")

  
    Dim doc As JavaObject
    doc.InitializeNewInstance("com.itseasy.rtf.RTFDocument",Array(PageSize.GetField("DIN_A4_QUER")))
    doc.RunMethod("setViewscale",Array(doc.GetField("VIEWSCALE_FULLPAGE")))
    doc.RunMethod("addParagraph",Array(Paragraph))
  

'  
    Dim jFile As JavaObject
    jFile.InitializeNewInstance("java.io.File",Array(File.Combine(File.DirRootExternal,"myfile.doc")))
  

    doc.RunMethod("save",Array(jFile))
  

    Paragraph.RunMethod("addText",Array(TextPart))
  
    doc.RunMethod("getDocument",Null)

My attempts were a year or two ago but this code worked for me

Please find library documentation to add more , my internet connection is at its worst now :(

I don't know whether this library will fulfil your needs but you might give it a shot
 

Attachments

  • srw.jar
    28.5 KB · Views: 224
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
I have had some success accessing this library using JavaObject
I don't know whether this library will fulfil your needs but you might give it a shot

Wow ! Thanks !.
It's lib from here http://it-s-easy.com/download/srw_de.htm

But it's an issue with national letters. Instead of RU text "Русский текст" i can see "B0D3D1D1CaC8C9 D2C5CaD1D2" in the result file open in :(
It looks like a font issue. But the author seemed to be german - so must be a way to use umlauts and other UTF symbols.... How ?
 
Last edited:
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Looks like this is placed as base64encoded string maybe? Looks like this or not?
I believe this function should be edited

B4X:
   private String getHeader() {
        return "\\rtf" + RTFVERSION             // RTF Version, damit beginnt jedes RTF Dokument
             + "\\ansi\\ansicpg1252"            // <charset>    -> Default, ANSI mit Mitteleuropنischen Zeichensatz
             + "\\deff" + this.deffont.getFontnumber() + "{" + getFonttable() + "}"        // <fonttbl>    -> Schriftentabelle
             + "{" + getColortable() + "}"        // <colortbl>    -> Farbtabelle
             // \stylesheet ... http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnrtfspec/html/rtfspec_6.asp
             + "{\\*\\generator " + GENERATOR + ";}";    // Generatorname
    }
It should be edited and recompiled or maybe you do your magic :D
If I got some time I will try to do it
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
I believe this function should be edited
+ "\\ansi\\ansicpg1252" // <charset> -> Default, ANSI mit Mitteleuropنischen Zeichensatz

Replaceing "ansicpg1252" into another charset in the result file - nothing good for viewing :-(

But if to re-save the result .DOC by WPS Office Writer - the new .DOC contains RU text in UNICODE
B4X:
{\uc1 \u168 ?}{\uc1 \u183 ?}{\uc1 \u711 ?}{\uc1 \u713 ?}{\uc1 \u8213 ?}{\uc1 \u8214 ?}{\uc1 \u8217 ?}{\uc1 \u8221 ?}{\uc1 \u8230 ?}{\uc1 \u8758 ?}{\uc1 \u12289 ?}{\uc1 \u12290 ?}{\uc1 \u12291 ?}{\uc1 \u12293 ?}{\uc1 \u12297 ?}{\uc1 \u12299 ?}{\uc1 \u12301 ?}{\uc1 \u12303 ?}{\uc1 \u12305 ?}{\uc1 \u12309 ?}{\uc1 \u12311 ?}{\uc1 \u65281 ?}{\uc1 \u65282 ?}{\uc1 \u65287 ?}{\uc1 \u65289 ?}{\uc1 \u65292 ?}{\uc1 \u65294 ?}{\uc1 \u65306 ?}{\uc1 \u65307 ?}{\uc1 \u65311 ?}{\uc1 \u65341 ?}{\uc1 \u65344 ?}{\uc1 \u65372 ?}{\uc1 \u65373 ?}{\uc1 \u65374 ?}{\uc1 \u65504 ?}}{\*\lchars ([\'7b{\uc1 \u183 ?}{\uc1 \u8216 ?}{\uc1 \u8220 ?}{\uc1 \u12296 ?}{\uc1 \u12298 ?}{\uc1 \u12300 ?}{\uc1 \u12302 ?}{\uc1 \u12304 ?}{\uc1 \u12308 ?}{\uc1 \u12310 ?}{\uc1 \u65288 ?}{\uc1 \u65294 ?}{\uc1 \u65339 ?}{\uc1 \u65371 ?}{\uc1 \u65505 ?}{\uc1 \u65509 ?}...................
And replaced ansicpg1252 into RU charset ansicpg1251.
 
Last edited:
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Replaceing "ansicpg1252" into another charset in the result file - nothing good for viewing :-(

But if to re-save the result .DOC by WPS Office Writer - the new .DOC contains RU text in UNICODE
B4X:
{\uc1 \u168 ?}{\uc1 \u183 ?}{\uc1 \u711 ?}{\uc1 \u713 ?}{\uc1 \u8213 ?}{\uc1 \u8214 ?}{\uc1 \u8217 ?}{\uc1 \u8221 ?}{\uc1 \u8230 ?}{\uc1 \u8758 ?}{\uc1 \u12289 ?}{\uc1 \u12290 ?}{\uc1 \u12291 ?}{\uc1 \u12293 ?}{\uc1 \u12297 ?}{\uc1 \u12299 ?}{\uc1 \u12301 ?}{\uc1 \u12303 ?}{\uc1 \u12305 ?}{\uc1 \u12309 ?}{\uc1 \u12311 ?}{\uc1 \u65281 ?}{\uc1 \u65282 ?}{\uc1 \u65287 ?}{\uc1 \u65289 ?}{\uc1 \u65292 ?}{\uc1 \u65294 ?}{\uc1 \u65306 ?}{\uc1 \u65307 ?}{\uc1 \u65311 ?}{\uc1 \u65341 ?}{\uc1 \u65344 ?}{\uc1 \u65372 ?}{\uc1 \u65373 ?}{\uc1 \u65374 ?}{\uc1 \u65504 ?}}{\*\lchars ([\'7b{\uc1 \u183 ?}{\uc1 \u8216 ?}{\uc1 \u8220 ?}{\uc1 \u12296 ?}{\uc1 \u12298 ?}{\uc1 \u12300 ?}{\uc1 \u12302 ?}{\uc1 \u12304 ?}{\uc1 \u12308 ?}{\uc1 \u12310 ?}{\uc1 \u65288 ?}{\uc1 \u65294 ?}{\uc1 \u65339 ?}{\uc1 \u65371 ?}{\uc1 \u65505 ?}{\uc1 \u65509 ?}...................
And replace ansicpg1252 into RU charset ansicpg1251.
I started wrapping it :) Wish me good luck
 
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
I am sorry I could not go beyond what we have achieved through JavaObject but I am trying .
I think DonManfred also started wrapping this library and you know what does that mean :)
However , I will keep trying .
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I think DonManfred also started wrapping this library
not really. Just wanted to try the sample to see if it works
At the beginning of this thread i thought it will not work. But i got the sampe running (see my answer in the other thread) so i´m positive it will work.
But at this point it is really just the sample code which i compiled. But it works! At least with german umlauts.

PD: I can give you the source of the srw.jar. Seeing the source java files (and the methods containing) may help you to come further with javaobject.
 

Attachments

  • srw.zip
    89.4 KB · Views: 215
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I also tried with german text, but "Geschäftsprozesse" in DOC is "Geschдftsprozesse". Red is RU letter instead of "ä".
see attachment in post #13

Edit: Sorry, wrong attachment... wait

Edit2: See here

It is OK (i forgot to replace two or three issues but basically it works)
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Don, so did you compile any new version of this lib ? To try.
 
Upvote 0
Top