Click here to Skip to main content
15,887,285 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The goal:
be able to distribute our APP with any LIBs required to manage replacement on client side with no Microsoft dependency (and licenses == $$)
OR
Any other tips you may have to allow us to get a fixed .DOC/.ODT file + Oracle data to create a custom letter and open it to final user to edit for details.

If you any sugestion about alternative options I´ll be glad to ear you!

Right now I have a SW using MS Interop as below:

VB
'-------------- Código principal -------------------------------------------

Microsoft.Office.Interop.Word.Application oApp;
Microsoft.Office.Interop.Word.Document oDoc;

object missing = Missing.Value;
object readOnly = false;
object isVisible = false;
object template = ArquivoOrigem;

oApp = new Microsoft.Office.Interop.Word.Application();
oDoc = oApp.Documents.Open(ref ArquivoDestino, ref missing,
	ref readOnly, ref missing, ref missing, ref missing,
	ref missing, ref missing, ref missing, ref missing,
	ref missing, ref isVisible, ref missing, ref missing,
	ref missing, ref missing);
oDoc.Activate();

ReplaceVariable(oDoc, "#NAME#", "JOHN");

   oDoc.Save();
object saveChanges = Microsoft.Office.Interop.Word.WdSaveOptions.wdSaveChanges;
oApp.Quit(ref saveChanges, ref missing, ref missing);
				
'------ Função ReplaceVariable -------------------------------------------
				
private static void ReplaceVariable(Microsoft.Office.Interop.Word.Document oDoc, object FindText, object ReplaceWith)
{
	object MatchWholeWord = true;
	object Foward = false;
	object missing = Missing.Value;
	Microsoft.Office.Interop.Word.Range oRng;

	oRng = oDoc.Range(ref missing, ref missing);

	oRng.Find.Execute(ref FindText, ref missing, ref MatchWholeWord, ref missing, ref missing,
				   ref missing, ref missing, ref missing, ref missing, ref ReplaceWith,
				   ref missing, ref missing, ref missing, ref missing, ref missing);

	oRng = oDoc.Range(ref missing, ref missing);
}
'--------------- end of code ------------


This allow us to have a template document and use our SW to replace fields with values from a Oracle database.

Now we´d like to remove this Microsoft dependency and use just LibreOffice/OpenOffice (free/open) solutions.

Any tips ?

What I have tried:

Just used Microsoft Interop solution since ever... no idea where to start to change to ODT libraries.
Posted
Updated 8-Jan-18 3:18am
v2

You can take a look at the Open XML SDK, Welcome to the Open XML SDK 2.5 for Office[^]
 
Share this answer
 
Comments
Maciej Los 4-Jan-18 10:33am    
LbreOffice is not the same as OpenXml...
I could swear I had posted here a reply, anyways here is the answer.
LibreOffice and other using ODF (OpenDocument Formats) do not need this DDE/Interop thing.

The format .ODT contains XML in a ZIP file.
So you can open the zip file, edit content.xml file and replace the #CLIENT_NAME# variable by whatever you like and save.
Just compress everything back on ZIP file and name it with ODT extension and everything works.

Here is a sample file I´ve create to test this on linux CLI:

you must call it as:
LO-subs.sh FILE.ODT ClientName PhoneNumber
where
1st parameter is filename where subs will occuour,
2nd parameter is the client name to replace variable ##cliente##
3rd parameter is the client phone number that will replace the ##Fone## variable
(see the variable in shell script).

[root@andorinha ~]# cat LO-subs.sh
Arquivo=$1
Nome=$2
Fone=$3
dest="/tmp/LOs1"

mkdir $dest

cp $Arquivo $dest/
cd $dest
unzip $Arquivo
sed -i "s/\#\#cliente\#\#/$Nome/" content.xml
sed -i "s/\#\#telefone\#\#/$Fone/" content.xml
zip $Arquivo *
cd $dest

I´ve used it sucessfully, so if someone need helps, please write an e-mail to my gmail account: jader.marasca

I´ll be glad to help!
 
Share this answer
 
No other solution ? OpenXML @ Microsoft do not appear to be a VIABLE solution.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900