在Excel文件中保存字符串内容如何? [英] Save String content in Excel File how?

查看:127
本文介绍了在Excel文件中保存字符串内容如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部,
我正在Visual Studio 2010中开发一个VB应用程序.现在我需要将字符串数据保存到Excel文件中.....每当有数据来自时,我就在此应用程序中使用Serialport .....该串行端口我将数据附加到一个字符串变量中.....现在,我需要将该字符串数据保存到Excel文件中..
给我指导以完成此任务.....

在ADV中表示感谢.......:)

Hai All,
I am Developing one VB Application in Visual Studio 2010. Now i need to Save String data into Excel file........ I am using Serialport in this application ........ whenever data has been coming from this serialport i append that data to one string variable..... Now i need to save that String data into Excel file.....
Give me direction to do this task........

Thanks in ADV....... :)

推荐答案

这只是我脑海中所希望的一些代码,希望对您有所帮助. />
this is just some code that i thourght of of the top of my head hope it helps.

Imports Microsoft.Office.Interop
Imports System.Runtime.InteropServices

Public Class Form_Main

Public MyExcel As New Excel.Application
public VarYourString1 as string = "your value"


sub Write_Data()
 MyExcel.Visible = True ' this will show the workbook in MS Excel
MyExcel.Sheets(Sheet1).Select() ' Sheet1, Sheet2, Sheet3 See this is Excel they need to be the same.



MyExcel.Range("A1048575").End(Excel.XlDirection.xlUp).Select() ' Select Last Used cell in A## ,    1048576 Max Rows

MyExcel.ActiveCell.Offset(1, 0).Select()' move down 1 cell
MyExcel.ActiveCell.Offset(0, 2).Select() move right 2 cells
MyExcel.ActiveCell.Offset(0, -1).Select() move left 1 cell


MyExcel.ActiveCell.Offset("A1").Select()' i havent tested this one



' you are looking for something like this
MyExcel.ActiveCell.Value = VarYourString1 ' this will enter "Your Value"
MyExcel.ActiveCell.Offset(1, 0).Select()' move down 1 cell

MyExcel.Workbooks.Close()' closes the Excel File

End Sub
End Class


这篇关于在Excel文件中保存字符串内容如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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