Club Builder - Foros de discusión Club Builder
Foro de C++Builder en español
 
 FAQFAQ   BuscarBuscar   MiembrosMiembros   Grupos de UsuariosGrupos de Usuarios   RegistrarseRegistrarse 
 PerfilPerfil   Entra para ver tus mensajes privadosEntra para ver tus mensajes privados   EntrarEntrar 

Automatizacion OLE para OpenOffice

 
Publicar nuevo tema   Responder al tema    Foros de discusión -> Consultas
Ver tema anterior :: Ver tema siguiente  
Autor Mensaje
Mensaje    Asunto: Automatizacion OLE para OpenOffice Responder citando

Hola a todos. Estoy interesado en comunicarme con writer de OpenOffice al igual que hacemos con el Word (insertar texto, insertar tablas, buscar y reemplazar texto....). He estado buscando por internet y hay muchas cosas para Visual Basic y VBScript. Si alguien me puede ayudar y poner algunos ejemplos de lo que he puesto entre paréntesis le estaría muy agradecido.
Saludos a todos.
Volver arriba
Ver perfil de usuario Enviar mensaje privado Enviar email MSN Messenger
Mensaje    Asunto: Responder citando

Con este código cargo un doc, lo modifico y lo guardo. Principalmente busca texto (en mi caso veras kXXX) y lo reemplaza, hay mucho comentado porque paré de codificar en cuanto hacia lo que necesitaba. Espero que para comenzar te sirva.

Un saludo.

Código:


String __fastcall TfInicial::FileURL(String cF)
{
return ("file:///" + StringReplace(cF, "\\", "/", TReplaceFlags() << rfReplaceAll));
}
//---------------------------------------------------------------------------

void __fastcall TfInicial::CreaDocOO(String cF)
{
Variant vWord, vDocs, vDoc, vSelB, vWTbl, MyOP, vBuscar;
std::auto_ptr<TextMLg> Mlu(new TextMLg(xAp.cRB + "\\Listas"));
String cpl;

try {
   vWord = CreateOleObject("com.sun.star.ServiceManager");
   if (VarType(vWord) == varDispatch) {
      vDocs = vWord.OleFunction("CreateInstance", "com.sun.star.frame.Desktop");

      Variant vOOparm(OPENARRAY(int, (0,0)), varVariant);
      Variant vEmpty(OPENARRAY(int, (0,-1)), varInteger);

//      MyOP = vWord.OleFunction("Bridge_GetStruct", "com.sun.star.beans.PropertyValue");
//      MyOP.OlePropertySet("name","Hidden");
//      MyOP.OlePropertySet("value", false);
//      vOOparm.PutElement(MyOP, 0);

      vDoc = vDocs.OleFunction("LoadComponentFromURL",
                        FileURL(cF).c_str(), "_blank", VT_EMPTY, vOOparm);
//      vDoc = vDocs.LoadComponentFromURL(("File:///" + cF).c_str(), "_blank", VT_EMPTY, vOOparm);

      //vBuscar = vDoc.CreateObject("createReplaceDescriptor");
      vBuscar = vDoc.OleFunction("createReplaceDescriptor" );
      //vBuscar.OleProcedure("SearchString", kNRS);
      vBuscar.OlePropertySet("SearchString", kNRS);
      vBuscar.OlePropertySet("ReplaceString", IntToStr(xR.nRs).c_str());
      vDoc.OleProcedure("ReplaceAll", vBuscar);

      vBuscar.OlePropertySet("SearchString", kDHT);
      vBuscar.OlePropertySet("ReplaceString", xR.cH.c_str());
      vDoc.OleProcedure("ReplaceAll", vBuscar);

      vBuscar.OlePropertySet("SearchString", kFEN);
      vBuscar.OlePropertySet("ReplaceString", xR.dF.FormatString("dd-mm-yy").c_str());
      vDoc.OleProcedure("ReplaceAll", vBuscar);

      vBuscar.OlePropertySet("SearchString", kFSL);
      vBuscar.OlePropertySet("ReplaceString", xR.d2.FormatString("dd-mm-yy").c_str());
      vDoc.OleProcedure("ReplaceAll", vBuscar);

      vBuscar.OlePropertySet("SearchString", kNNS);
      vBuscar.OlePropertySet("ReplaceString", IntToStr(xR.nD).c_str());
      vDoc.OleProcedure("ReplaceAll", vBuscar);

      if (xR.nTP>0) {  //plantilla en tabla
         String cDs;
         if (xR.nG==0) { //idividual
            vBuscar.OlePropertySet("SearchString", kNMC);
            vBuscar.OlePropertySet("ReplaceString", xR.cN.c_str());
            vDoc.OleProcedure("ReplaceAll", vBuscar);
         } else {
            cpl = Mlu->TextLgMI("GRUPO", xR.cI) + ": " + xR.cG;
            vBuscar.OlePropertySet("SearchString", kNMC);
            vBuscar.OlePropertySet("ReplaceString", cpl.c_str());
            vDoc.OleProcedure("ReplaceAll", vBuscar);
         }
         for (int i = 0; i < aDg.Count(); i++) {
            cpl = FloatToStrF(aDg[i]->nPt * aDg[i]->nH * xR.nD, ffFixed, 12, 2);
            if (i > 0)
               cDs += '\r';
            cDs += '\t';
            cDs += (IntToStr(aDg[i]->nH) +'\t');
            cDs += (aDg[i]->cds + '\t');
            cDs += (Mlu->TextLgMI(aRg[aDg[i]->nX], xR.cI) + '\t');
            cDs += (IntToStr(aDg[i]->nH * aDg[i]->nP) + '\t');
            if (xR.nPD>0) {
               cDs += (FloatToStrF(aDg[i]->nPt, ffFixed, 12, 2) + '\t');
            } else {
               cDs += (FloatToStrF(aDg[i]->nP0, ffFixed, 12, 2) + '\t');
            }
            //if ((aDg.Count()>1) ||(aDg[i]->nH>1))
               cDs += cpl; //siempre??
         }

         vBuscar.OlePropertySet("SearchString", kTAB);
         vBuscar.OlePropertySet("ReplaceString", cDs.c_str());
         vDoc.OleProcedure("ReplaceAll", vBuscar);

      } else if (xR.nG==0) {
         String crg = Mlu->TextLgMI(aRg[xR.nR], xR.cI);
         vBuscar.OlePropertySet("SearchString", kNMC);
         vBuscar.OlePropertySet("ReplaceString", xR.cN.c_str());
         vDoc.OleProcedure("ReplaceAll", vBuscar);

         vBuscar.OlePropertySet("SearchString", kDSR);
         vBuscar.OlePropertySet("ReplaceString", xR.cds.c_str());
         vDoc.OleProcedure("ReplaceAll", vBuscar);

         vBuscar.OlePropertySet("SearchString", kNPX);
         vBuscar.OlePropertySet("ReplaceString", IntToStr(xR.nP).c_str());
         vDoc.OleProcedure("ReplaceAll", vBuscar);

         vBuscar.OlePropertySet("SearchString", kPXD);
         vBuscar.OlePropertySet("ReplaceString", xR.cpd.c_str());
         vDoc.OleProcedure("ReplaceAll", vBuscar);

         vBuscar.OlePropertySet("SearchString", kTRG);
         vBuscar.OlePropertySet("ReplaceString", crg.c_str());
         vDoc.OleProcedure("ReplaceAll", vBuscar);

         } else { //--- grupos (en base a una tabla.
            Variant vLin;
            vBuscar.OlePropertySet("SearchString", kNMG);
            vBuscar.OlePropertySet("ReplaceString", xR.cG.c_str());
            vDoc.OleProcedure("ReplaceAll", vBuscar);

            vSelB = vDoc.OleFunction("getBookmarks"); //sabemos q hay 1
            vLin = vSelB.OleFunction("getByName", kTBL); //sabemos q hay 1
            vBuscar = vLin.OleFunction("getAnchor");
   //         String crg;
   //         for (int i = 0; i < aDg.Count(); i++) {
   //            crg = Mlu->TextLgMI(aRg[aDg[i]->nX], xR.cI);
   //            if (i > 0) {                                                   //(Variant)
   //               vSeleccion = vWTbl.OlePropertyGet("Rows").OleFunction(kKIT, i+1);
   //               vSeleccion.OleProcedure("Select");
   //               vWord.OlePropertyGet(kKSN).OleProcedure("InsertRowsBelow", 1);
   //            }
   //            vLin = i+2;
   //            vSeleccion = vWTbl.OleFunction(kKCL, vLin, 1);   //Hab
   //            vSeleccion.OlePropertyGet(kKRN).
   //                  OlePropertySet(kKTX, IntToStr(aDg[i]->nH).c_str());
   //            vSeleccion = vWTbl.OleFunction(kKCL, vLin, 2);  //Serv.
   //            vSeleccion.OlePropertyGet(kKRN).
   //                  OlePropertySet(kKTX, aDg[i]->cds.c_str());
   //            vSeleccion = vWTbl.OleFunction(kKCL, vLin, 3);   //Reg.
   //            vSeleccion.OlePropertyGet(kKRN).
   //                  OlePropertySet(kKTX, crg.c_str());
   //
   //
   //            vSeleccion = vWTbl.OleFunction(kKCL, vLin, 4);   //Pax.
   //            vSeleccion.OlePropertyGet(kKRN).
   //                  OlePropertySet(kKTX, IntToStr(aDg[i]->nH*aDg[i]->nP).c_str());
   //
   //            cpl = FloatToStrF(aDg[i]->nPt, ffFixed, 12, 2);
   //            vSeleccion = vWTbl.OleFunction(kKCL, vLin, 5);    //Precio
   //            vSeleccion.OlePropertyGet(kKRN).OlePropertySet(kKTX, cpl.c_str());
   //         }

            vSelB = vLin = Unassigned();
         }

//         //kPTA
      cpl = FloatToStrF(xR.nAn, ffFixed, 12, 2);
      vBuscar.OlePropertySet("SearchString", kPTA);
      vBuscar.OlePropertySet("ReplaceString", cpl.c_str());
      vDoc.OleProcedure("ReplaceAll", vBuscar);
//
      vBuscar.OlePropertySet("SearchString", kPTT);
      vBuscar.OlePropertySet("ReplaceString", xR.cpt.c_str());
      vDoc.OleProcedure("ReplaceAll", vBuscar);
//
      vBuscar.OlePropertySet("SearchString", kDII);
      vBuscar.OlePropertySet("ReplaceString", xR.cdi.c_str());
      vDoc.OleProcedure("ReplaceAll", vBuscar);
//
      vBuscar.OlePropertySet("SearchString", kNLC);
      vBuscar.OlePropertySet("ReplaceString", xR.cL.c_str());
      vDoc.OleProcedure("ReplaceAll", vBuscar);
//
//      //Opcional Comisión
      if (xR.nCm > 0) {
         cpl = IntToStr(xR.nCm) + "% " + Mlu->TextLgMI("COMISION", xR.cI);
//         vSeleccion = vWord.OlePropertyGet(kKSN);
//         //--- esto inserta texto-   en word: Insertar/Marcador...
//         vSeleccion.OleProcedure("Goto", -1,   VT_EMPTY,   VT_EMPTY, "xcmn");
//         vSeleccion.OleProcedure("TypeText", cpl.c_str());
      }
      //last
      vBuscar.OlePropertySet("SearchString", kNMO);
      vBuscar.OlePropertySet("ReplaceString", xAp.cCT.c_str());
      vDoc.OleProcedure("ReplaceAll", vBuscar);
      vBuscar.OlePropertySet("SearchString", kEML);
      vBuscar.OlePropertySet("ReplaceString", xAp.cDs.c_str());
      vDoc.OleProcedure("ReplaceAll", vBuscar);

      vDoc.OleFunction("Store");

      vDocs = vDoc = vOOparm = vBuscar = Unassigned;

   }
   vWord = Unassigned;



} catch (const Exception &E) {
   ShowMessage( E.Message);
   xAp.nR = 1;
}
vWord = vDocs = vDoc = vBuscar = Unassigned;  //vSeleccion =

}
//---------------------------------------------------------------------------

Volver arriba
Ver perfil de usuario Enviar mensaje privado
Mensaje    Asunto: Responder citando

Muchísimas gracias Juanma. Era justo lo que necesitaba. Voy a ponerlo en práctica. Gracias a todos por estar siempre ahí!! Saludos!!
Volver arriba
Ver perfil de usuario Enviar mensaje privado Enviar email MSN Messenger
Mensaje    Asunto: Tratamiento de tablas Responder citando

Ahora me ha surgido la opción de crear una tabla, o en una ya existente, y poner valores en determinadas celdas (insertar filas, borrar filas, colorear fondo celda.....). No tendrás ningún ejemplo al respecto?
Volver arriba
Ver perfil de usuario Enviar mensaje privado Enviar email MSN Messenger
Mostrar mensajes de anteriores:   
Cambiar a:  
No puedes publicar temas nuevos en este foro
No puedes responder a temas en este foro
No puedes editar tus mensajes en este foro
No puedes borrar tus mensajes en este foro
No puedes votar en las encuestas de este foro


Hosting WordPress Indedmedia desde 3,99 €
© 2002–2026 Club Builder · Funciona con phpBB.