使用cmd/batch文件将文本字符串添加到html文档中 [英] Add a string of text into a html document using cmd/batch file

查看:87
本文介绍了使用cmd/batch文件将文本字符串添加到html文档中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在html文档中添加文本字符串.
我的网站有一个更新"部分,您可以在其中看到他们开车去的地方. (一些摩托车手的网站)
我想这样做,所以我父亲只需要打开bat文件类型一点信息,然后它将字符串添加到html文档中.
我目前正在使用表格"作为布局.
这是代码:

I would like to add a string of text into a html document.
My website has an "update" part where you can see where they drove to. (Its a website for some bikers)
I would like to do it so my dad just need to open a bat file type a little information and then it would add the string to the html document.
Im currently using a "table" as the layout.
This is the code:

 <tr style="mso-yfti-irow:34">
    <td valign="top" style="width:180;padding-left:3.5pt; padding-light:3.5pt; padding-top:0cm; padding-bottom:0cm" height="5">
        <font size="4">DATE</font>
    </td>
    <td valign="top" style="width:500;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm" height="5">
         <font size="4">LOCATION</font></td>
    <td valign="top" style="width:523;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm" height="5">
        <font size="4">AMOUNT</font>
    </td>
 </tr>


当前网站

<html>
    <head>
        Some things here....
    </head>
    <body>
        <div>
            More things here
        </div>
        <table>
            the table/the place where new text should be added
        </table>
        A bit more
    </body>
 </html>    


我的意思是,我可以用这段代码

What I was thing was that I could make a bat file with this code

echo off
set /p Date="Date: "
set /p Location="Location: "
set /p Amount="Amount: "

(some command here to add it)

<tr style="mso-yfti-irow:34">
    <td valign="top" style="width:180;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm" height="5">
    <font size="4">%Date%</font></td>
    <td valign="top" style="width:500;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm" height="5">
    <font size="4">%Location%</font></td>
    <td valign="top" style="width:523;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm" height="5">
    <font size="4">%Amount%</font></td>
</tr>

Exit


新文本应始终添加在表格的底部,而不是html文档的底部
行nr.也会永远改变
我希望我已经对此做了足够的解释,如果您不了解某些内容,然后再写,那么我会尽力澄清


New text should always be added at the bottom of the table, however not the bottom of the html document
The line nr. will also always change
I hope I explained this well enough, if there was something you didn't understand then just write, then I'll try to clarify

推荐答案

听起来像您已经写了蝙蝠脚本来提示您的父亲输入值.因此,我将重点介绍如何将这些内容插入您的html页面.

Sounds like you already have the bat script written to prompt your dad for the values. So I will focus on how to insert those into your html page.

在当前的html文件中,更改表格末尾的格式,将最后一个</tr>直接在</table>

In your current html file, change the formatting of the end of your table, placing the last </tr> directly in front of the </table>

</tr></table>

在您的bat文件中,替换

in your bat file, replace

(some command here to add it)
<tr style="mso-yfti-irow:34">
   <td valign="top" style="width:180;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm" height="5">
   <font size="4">%Date%</font></td>
   <td valign="top" style="width:500;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm" height="5">
   <font size="4">%Location%</font></td>
   <td valign="top" style="width:523;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm" height="5">
   <font size="4">%Amount%</font></td>
   </tr>

与此

powershell -command "(Get-Content Name_of_File.html) -replace '</tr></table>', '<tr style=&quot;mso-yfti-irow:34&quot;> <td valign=&quot;top&quot; style=&quot;width:180;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm&quot; height=&quot;5&quot;><font size=&quot;4&quot;>%Date%</font></td><td valign=&quot;top&quot; style=&quot;width:500;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm&quot; height=&quot;5&quot;><font size=&quot;4&quot;>%Location%</font></td><td valign=&quot;top&quot; style=&quot;width:523;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm&quot; height=&quot;5&quot;><font size=&quot;4&quot;>%Amount%</font></td></tr></table>' | Set-Content Name_of_File.html"
Powershell.exe -executionpolicy remotesigned -File replace_quot.ps1

这将从您的批处理脚本中执行PowerShell搜索和替换命令,以找到</tr></table>.并将其替换为新行.每次您父亲在页面上添加新行程时,都会将信息添加到表格底部.

This will execute a PowerShell search and replace command from within your batch script to find </tr></table> and replace it with the new row. Each time your dad adds a new trip to the page, it will add the information to the bottom of the table.

powershell -command 使批处理知道执行作为powershell的双引号"之间的所有操作. get-content读取您的html文件.因此,将 Name_of_File.html 替换为HTML页面的名称.

The powershell -command lets batch know to execute everthing between the "double quotes" as powershell. The get-content reads your html file. So replace Name_of_File.html with the name of your HTML page.

命令的下一部分执行搜索和替换.您必须使用& quot; semi;而是使用"来使powershell读取整个行作为一组流畅的动作.它将编写HTML代码,并将%Date%,%Location%和%Amount%的变量用作新值.

The next part of the command performs a search and replace. You must use &quot; instead " for powershell to read the entire line as a fluid set of actions. It will write the HTML code and use your variables of %Date%, %Location% and %Amount% for the new values.

然后使用 set-content 将文件写回到html页面.因此,请确保在此处更新 Name_of_File.html 以及HTML页面的名称.

The file is then written back to the html page using set-content. So make sure the Name_of_File.html is updated here as well with the name of your HTML page.

将以下行保存在名为 replace_quot.ps1 的其他脚本中,并将此脚本放置在与bat文件相同的目录中.

Save the following line in a different script named replace_quot.ps1 and place this script in the same directory as your bat file.

(Get-Content Name_of_File.html) -replace '&quot;', '"' | set-content Name_of_File.html

您的bat文件将调用此脚本来替换& qout;.在您的html文件中包含实际的"字符.

This script will be called by your bat file to replace the &qout; with the actual " character in your html file.

这篇关于使用cmd/batch文件将文本字符串添加到html文档中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆