将字符串数据保存到Excel文件中,而不是从DataGrid中保存(从VB6到VB.NET) [英] Save String Data into Excel file not from DataGrid (VB6 to VB.NET)

查看:75
本文介绍了将字符串数据保存到Excel文件中,而不是从DataGrid中保存(从VB6到VB.NET)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部,
我需要实现该功能.即,字符串数据已保存到Excel文件中.
我已经在VB6中为这些操作开发了代码. 但是在VB.NET中,我不知道如何获得它..
请任何人帮助我.
这是我的VB6代码...
表格加载后

Hai All,
I need to implement the function., ie., String data has been saved into Excel file.
Already i develop code for these operation in VB6 ..
But in VB.NET i don''t know how to get it..
Please any body help me.
Here is my VB6 Code...
When form has been load

Data1.Connect = "Excel 8.0"
Data1.DatabaseName = CurDir & "\" & "data.xls"
Data1.RecordSource = "Sheet1$"
Data1.Refresh
If Err <> 0 Then
    MsgBox "Select Excel File"
    Alarmcmd.Visible = False
End if


结束
并将数据写入Excel中的各个字段



And this to write the data to the respective fields in Excel

alm.Data1.Recordset("ALARM") = "DG Low Fuel"


alm.Data1.Recordset("ALARM") = "Smoke/Fire"


alm.Data1.Recordset("DATE") = Mid(rxd, alarm_count, 2) & "/" & Mid(rxd, alarm_count + 2, 2) & "/" & Mid(rxd, alarm_count + 2 + 2, 2)


这是用于在Excel中更新和保存数据的


and this is to update and save the data in Excel

alm.Data1.Recordset.Update
            alm.Data1.Refresh




我如何在VB.NET中执行相同的任务..............
请帮助我.




How i need to do the same task in VB.NET...........
Please help me.

推荐答案

数据1.刷新 如果Err < > 0然后 MsgBox选择Excel文件" Alarmcmd.Visible = False 如果
" Data1.Refresh If Err <> 0 Then MsgBox "Select Excel File" Alarmcmd.Visible = False End if


结束
并将数据写入Excel中的各个字段



And this to write the data to the respective fields in Excel

alm.Data1.Recordset("ALARM") = "DG Low Fuel"


alm.Data1.Recordset("ALARM") = "Smoke/Fire"


alm.Data1.Recordset("DATE") = Mid(rxd, alarm_count, 2) & "/" & Mid(rxd, alarm_count + 2, 2) & "/" & Mid(rxd, alarm_count + 2 + 2, 2)


这是用于在Excel中更新和保存数据的


and this is to update and save the data in Excel

alm.Data1.Recordset.Update
            alm.Data1.Refresh




我如何在VB.NET中执行相同的任务..............
请帮助我.




How i need to do the same task in VB.NET...........
Please help me.


自从我使用VB6以来已经很久了,所以我无法确切地记住您所使用的技术.但是,使用.Net,修改Excel文件的一种方法是使用Interop.

此主题的链接很少(不按任何顺序排列):
-如何从Visual Basic .NET自动执行Excel以通过使用数组填充或获取范围内的数据 [ ^ ]
-如何从Visual Basic .NET自动化Microsoft Excel [使用VB.Net导出到Excel [ Microsoft.Office.Interop.Excel命名空间 [ ^ ]
It''s been ages since I''ve used VB6 so I''m unable to remember exactly what was the technique you have used. But with .Net, one way to modify an Excel file is to use Interop.

Few links for this topic (not in any order):
- How to automate Excel from Visual Basic .NET to fill or to obtain data in a range by using arrays[^]
- How to automate Microsoft Excel from Visual Basic .NET[^]
- Export to Excel using VB.Net[^]
- Microsoft.Office.Interop.Excel Namespace [^]


这篇关于将字符串数据保存到Excel文件中,而不是从DataGrid中保存(从VB6到VB.NET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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