将HTML文件转换为CSV / TXT并通过Windows窗体将其插入数据库(visual studio C#) [英] Convert a HTML file into CSV/TXT and insert it into database via windows form(visual studio C#)

查看:178
本文介绍了将HTML文件转换为CSV / TXT并通过Windows窗体将其插入数据库(visual studio C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi,
   I want to convert a incoming html file into csv/txt and I have a windows form through which i want to the insert that file's data into database(MYSQL).
The data will get inserted into the textboxes and then it will get inserted into table's column accordingly.
Also I'm actually scanning a ID's QR code from Android app through which on sharing I get the HTML data.
Is there anyway that it could fetch that file and then automatically import that file convert it and then import it or anything??

What should I do?
I have searched alot but not getting anything.
I want the latest text file to be inserted.





我尝试了什么:



1.我已成功制作一个表格,将数据从文本框插入数据库到表格列。

2.我写了一个powershell命令将html文件转换为txt,它会删除html标记并相应地分隔数据。

3. powershell命令导出带有系统日期戳的文件。



批处理文件命令是这样的:



powershell -Command(gc bluetooth_content_share.html)-replace'< [^>] +>',''| Out-File bluetooth_content_share.txt





powershell -Command(gc bluetooth_content_share.txt)-replace'名称:',''| Out-File bluetooth_content_share.txt



powershell -Command(gc bluetooth_content_share.txt)-replace'UID:',','| Out-File bluetooth_content_share.txt



powershell -Command(gc bluetooth_content_share.txt)-replace'性别:',','| Out-File bluetooth_content_share.txt



powershell -Command(gc bluetooth_content_share.txt)-replace'出生日期:',','| Out-File bluetooth_content_share.txt



powershell - 命令(gc bluetooth_content_share.txt) -replace'Street:',','| Out-File bluetooth_content_share.txt



powershell -Command(gc bluetooth_content_share.txt)-replace'地址:' ,','| Out-File bluetooth_content_share.txt



powershell -Command(gc bluetooth_content_share.txt)-replace'Village:',','| Out-File bluetooth_content_share.txt



powershell -Command(gc bluetooth_content_share.txt)-replace'District:',','| Out-File bluetooth_content_share.txt



powershell -Command(gc bluetooth_content_share.txt)-replace'State:',','| Out-File bluetooth_content_share.txt



powershell -Command(gc bluetooth_content_share.txt)-replace'Pincode:',','| Out-File bluetooth_content_share.txt



powershell -Command(gc bluetooth_content_share.txt)-replace'City:',','| Out-File bluetooth_content_share.txt



powershell -Command(gc bluetooth_content_share.txt)| Set-Content -Encoding utf8 bluetooth_content_share.txt





renbluetooth_content_share.txtbluetooth_content_share-%date:~10,4% %date:~7,2 %% date:~4,2% - %time:~0,2 %% time:~3,2%.txt



What I have tried:

1.I have successfully made a form that inserts data into database from the textboxes into the table columns.
2.I have written a powershell command that converts the html file into txt, it removes the html tags and delimits the data accordingly.
3.The powershell command exports the file with system date stamp.

The batch file command is something like this:

powershell -Command "(gc bluetooth_content_share.html) -replace '<[^>]+>', '' | Out-File bluetooth_content_share.txt"


powershell -Command "(gc bluetooth_content_share.txt) -replace 'Name : ', '' | Out-File bluetooth_content_share.txt"

powershell -Command "(gc bluetooth_content_share.txt) -replace 'UID : ', ',' | Out-File bluetooth_content_share.txt"

powershell -Command "(gc bluetooth_content_share.txt) -replace 'Gender : ', ',' | Out-File bluetooth_content_share.txt"

powershell -Command "(gc bluetooth_content_share.txt) -replace 'Date of Birth : ', ',' | Out-File bluetooth_content_share.txt"

powershell -Command "(gc bluetooth_content_share.txt) -replace 'Street : ', ',' | Out-File bluetooth_content_share.txt"

powershell -Command "(gc bluetooth_content_share.txt) -replace 'Address : ', ',' | Out-File bluetooth_content_share.txt"

powershell -Command "(gc bluetooth_content_share.txt) -replace 'Village : ', ',' | Out-File bluetooth_content_share.txt"

powershell -Command "(gc bluetooth_content_share.txt) -replace 'District : ', ',' | Out-File bluetooth_content_share.txt"

powershell -Command "(gc bluetooth_content_share.txt) -replace 'State : ', ',' | Out-File bluetooth_content_share.txt"

powershell -Command "(gc bluetooth_content_share.txt) -replace 'Pincode : ', ',' | Out-File bluetooth_content_share.txt"

powershell -Command "(gc bluetooth_content_share.txt) -replace 'City : ', ',' | Out-File bluetooth_content_share.txt"

powershell -Command "(gc bluetooth_content_share.txt) | Set-Content -Encoding utf8 bluetooth_content_share.txt


ren "bluetooth_content_share.txt" "bluetooth_content_share-%date:~10,4%%date:~7,2%%date:~4,2%-%time:~0,2%%time:~3,2%.txt"

推荐答案

不是真的。 HTML文件是页面描述,CSV文件是逗号(和换行符)分隔的值列表 - 两种格式之间没有任何实际重叠,因此将通用HTML文件转换为任何格式的列表都不是真的很有用。



这就像试图将婚礼邀请转换成购物清单:它们根本不是一回事!



但是,HTML数据是文本,因此您可以将其直接存储到数据库中(假设您将其作为查询参数传递)。



但我认为你需要退后一步,更清楚地思考你到底要做什么 - 这个概念存在根本问题。
Not really. An HTML file is a page description, and a CSV file is a comma (and newline) separated list of values - there isn't any real overlap between the two formats so converting a generic HTML file to a list in any format isn't really going to work.

It's like trying to convert a wedding invitation to a shopping list: they aren't the same thing at all!

However, HTML data is text, so you could store it directly into a database (provided you pass it as a query parameter).

But I think you need to take a step back and think more clearly about exactly what you are trying to do - there are fundamental problems with this whole idea as described.


这篇关于将HTML文件转换为CSV / TXT并通过Windows窗体将其插入数据库(visual studio C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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