ASP - Modificar encabezados y pie de pagina en un word

 
Vista:
Imágen de perfil de Bet7o

Modificar encabezados y pie de pagina en un word

Publicado por Bet7o (17 intervenciones) el 14/07/2009 18:53:34
Hola a todos,

Tengo un script que me remplaza todas las coincidencias de un texto en un documento word, pero lo que no logro es poder remplazar tambien el encabezado y pie de pagina.

Les dejo el codigo que eh podido armas asta ahora.

<%@language="vbscript" lcid = "2058" codepage="65001"%>
<!--include file="nocache.asp"-->
<%
'On Error Resume Next
Response.Buffer = True
if request.ServerVariables("REQUEST_METHOD") = "POST" then
Function ReemplazarText(archivo, txtBuscar, txtRemplazar)
Set oWord = server.CreateObject("Word.Application")
oWord.Documents.open archivo
oWord.visible = false
Const wdFindContinue = 1
Const wdReplaceAll = 2
Set objSelection = oWord.Selection
With objSelection.Find
.Text = txtBuscar
.Forward = True
.MatchWholeWord = True
.Wrap = wdFindContinue
.Format = False
.Replacement.Text = txtRemplazar
.Execute ,,,,,,,,,,wdReplaceAll
End With
oWord.ActiveDocument.Save
oWord.Quit
Set oWord = Nothing
End Function
Call ReemplazarText ("E: ootDocAD-OBRA-FOSEG-SINANTICIPO.doc", Request("txt1"), Request("txt2"))
end if
if err.number <> 0 then
response.Write(err.description)
response.End()
end if
%>
<form action="gamasp.asp" method="post">
<table>
<tr>
<td>Buscar:</td>
<td><input type="text" name="txt1" value="" /></td>
</tr>
<tr>
<td>Reemplazar con:</td>
<td><input type="text" name="txt2" value="" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Aceptar" /></td>
</tr>
</table>
</form>

Con este codigo logro remplazar el texto pero no asi los encabezados y pie de pagina, investigando encontre como poner texto pero no reemplazar.

Este es el codigo:

With oWord.ActiveDocument.Sections(1)
.Headers(wdHeaderFooterEvenPages).Range.Text = "cab"
.Footers(wdHeaderFooterEvenPages).Range.Text = "pie"
End With

Espero alguien me pueda ayudar, saludos.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Bet7o

RE:Modificar encabezados y pie de pagina en un wor

Publicado por Bet7o (17 intervenciones) el 14/07/2009 19:24:39
Bueno pues aki les dejo la respuesta por si a alguien le sirve.

Saludos!
------------------------------------------------------------------------------------------------------
<%@language="vbscript" lcid = "2058" codepage="65001"%>
<!--include file="nocache.asp"-->
<%
'On Error Resume Next
Response.Buffer = True
if request.ServerVariables("REQUEST_METHOD") = "POST" then
Function ReemplazarText(archivo, txtBuscar, txtRemplazar)
Set oWord = server.CreateObject("Word.Application")
oWord.Documents.open archivo
oWord.visible = false
Const wdFindContinue = 1
Const wdReplaceAll = 2
Const wdHeaderFooterEvenPages = 1
With oWord.ActiveDocument.Sections(1)
With .Headers(wdHeaderFooterEvenPages).Range.Find
.Text = txtBuscar
.Forward = True
.MatchWholeWord = True
.Wrap = wdFindContinue
.Format = False
.Replacement.Text = txtRemplazar
.Execute ,,,,,,,,,,wdReplaceAll
End With
With .Footers(wdHeaderFooterEvenPages).Range.Find
.Text = txtBuscar
.Forward = True
.MatchWholeWord = True
.Wrap = wdFindContinue
.Format = False
.Replacement.Text = txtRemplazar
.Execute ,,,,,,,,,,wdReplaceAll
End With
End With
Set objSelection = oWord.Selection 'or Set objRange = objDoc.ActiveDocument.Range()
With objSelection.Find 'or With objRange.Find
.Text = txtBuscar
.Forward = True
.MatchWholeWord = True
.Wrap = wdFindContinue
.Format = False
.Replacement.Text = txtRemplazar
.Execute ,,,,,,,,,,wdReplaceAll
End With
oWord.ActiveDocument.Save
oWord.Quit
Set oWord = Nothing
End Function
Call ReemplazarText ("E: ootDoc" & Request("txt3"), Request("txt1"), Request("txt2"))
end if
if err.number <> 0 then
response.Write(err.description)
response.End()
end if
%>
<form action="gamasp.asp" method="post" enctype="application/x-www-form-urlencoded">
<table>
<tr>
<td>Buscar:</td>
<td><input type="text" id="txt1" name="txt1" value="" /></td>
</tr>
<tr>
<td>Reemplazar con:</td>
<td><input type="text" id="txt2" name="txt2" value="" /></td>
</tr>
<tr>
<td>Archivo:</td>
<td><input type="file" id="txt3" name="txt3" value="this.value" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Aceptar" /></td>
</tr>
</table>
</form>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar