用户登录
用户注册

分享至

spire.doc组件读取与写入word .net操作WORD的读取和写入

  • 作者: 老zzzzzzz公
  • 来源: 51数据库
  • 2020-04-21

Private Function CreaTable() As DataTable

Dim dt As New DataTable()

dt.Columns.Add("列1", GetType(String))

dt.Columns.Add("列2", GetType(Integer))

dt.Columns.Add("列3", GetType(String))

dt.Columns.Add("列4", GetType(String))

Dim row, row1 As DataRow

row = dt.NewRow()

row!列1 = "行1"

row!列2 = 1

row!列3 = "d"

row!列4 = "a"

dt.Rows.Add(row)

row1 = dt.NewRow()

row1!列1 = "行2"

row1!列2 = 12

row1!列3 = "b"

row1!列4 = "c"

dt.Rows.Add(row1)

Return dt

End Function

'2.将表中的内容导出到Excel

Dim xlApp As New Excel.Application()

Dim xlBook As Excel.Workbook

Dim xlSheet As Excel.Worksheet

Dim rowIndex As Integer = 1

Dim colIndex As Integer = 0

xlBook = xlApp.Workbooks().Add

xlSheet = xlBook.Worksheets("sheet1")

Dim Table As New DataTable()

Table = CreaTable()

'将所得到的表的列名,赋值给单元格

Dim Col As DataColumn

Dim Row As DataRow

For Each Col In Table.Columns

colIndex = colIndex + 1

xlApp.Cells(1, colIndex) = Col.ColumnName

Next

'得到的表所有行,赋值给单元格

For Each Row In Table.Rows

rowIndex = rowIndex + 1

colIndex = 0

For Each Col In Table.Columns

colIndex = colIndex + 1

xlApp.Cells(rowIndex, colIndex) = Row(Col.ColumnName)

Next

Next

With xlSheet

.Range(.Cells(1, 1), .Cells(1, colIndex)).Font.Name = "黑体"

'设标题为黑体字

.Range(.Cells(1, 1), .Cells(1, colIndex)).Font.Bold = True

'标题字体加粗

.Range(.Cells(1, 1), .Cells(rowIndex, colIndex)).Borders.LineStyle = 1

'设表格边框样式

End With

With xlSheet.PageSetup

.LeftHeader = "" & Chr(10) & "&""楷体_GB2312,常规""&10公司名称:" ' & Gsmc

.CenterHeader = "&""楷体_GB2312,常规""公司人员情况表&""宋体,常规""" & Chr(10) &_

"&""楷体_GB2312,常规""&10日 期:"

.RightHeader = "" & Chr(10) & "&""楷体_GB2312,常规""&10单位:"

.LeftFooter = "&""楷体_GB2312,常规""&10制表人:"

.CenterFooter = "&""楷体_GB2312,常规""&10制表日期:"

.RightFooter = "&""楷体_GB2312,常规""&10第&P页 共&N页"

End With

xlApp.Visible = True

'3.将表中的内容导出到WORD

Dim wordApp As New Word.Application()

Dim myDoc As Word.Document

Dim oTable As Word.Table

Dim rowIndex, colIndex As Integer

rowIndex = 1

colIndex = 0

wordApp.Documents.Add()

myDoc = wordApp.ActiveDocument

Dim Table As New DataTable()

Table = CreaTable()

oTable = myDoc.Tables.Add(Range:=myDoc.Range(Start:=0, End:=0), _

NumRows:=Table.Rows.Count + 1, NumColumns:=Table.Columns.Count)

'将所得到的表的列名,赋值给单元格

Dim Col As DataColumn

Dim Row As DataRow

For Each Col In Table.Columns

colIndex = colIndex + 1

oTable.Cell(1, colIndex).Range.InsertAfter(Col.ColumnName)

Next

'得到的表所有行,赋值给单元格

For Each Row In Table.Rows

rowIndex = rowIndex + 1

colIndex = 0

For Each Col In Table.Columns

colIndex = colIndex + 1

oTable.Cell(rowIndex, colIndex).Range.InsertAfter(Row(Col.ColumnName))

Next

Next

oTable.Borders.InsideLineStyle = 1

oTable.Borders.OutsideLineStyle = 1

wordApp.Visible = True

怎样用PHP读取一个word文档内容并在浏览器中显示出来?

传说中的phpword根本就不能读word文件,只能写,写完后可保存word,pdf.html等格式,网上一大把教程,都对读取避而不谈,都是一知半解粘贴过来骗积分的,就连官网上的手册也没有读的内容,想预览word,老老实实的在服务器上装插件吧。。。

如何用VB随机读取TXT中的内容,并将读取的内容写入WORD文档中

你好!

1、对于TXT文件,用什么语言都不能实现任意10条内容,只能从头开始读取;但可能有变通的办法:先产生一个随机数,打开TXT文件,从头开始读取数据,当已读取的数据=随机数时,开始将读取的数据放到变量中,连续存放10个;

2、用OFFICE的WORD文档控件的DLL链接到VB中,在VB中创建一个WORD文档工作平台(空间),将10个数据写入到该文档中,文档取名为www.DOC,最后保存该文档;

3、当然,若你对WORD文档控件的DLL用法不太了解的话,请参考MSDN或网络上查找,这里就不给出代码了,不好意思!

祝你成功!

C语言如何实现对txt文件的读取和写入

写入文件:

//---------------------------------------------------------------------------

#include <stdio.h>

int main(void)

{

char name[80],pas[80];

FILE *fp=fopen("user.txt","w");/*以写模式("w")打开文件user.txt,如果不存在,会自动创建*/

gets(name);

gets(pas); /*输入名称和密码*/

fputs(name,fp);

fputs(pas,fp);/*将名称和密码以字符串形式写入文件*/

fclose(fp);/*关闭文件*/

return 0;

}

//---------------------------------------------------------------------------

从文件读取:

//---------------------------------------------------------------------------

#include <stdio.h>

int main(void)

{

char name[80],pas[80];

FILE *fp=fopen("user.txt","r");/*以读模式("r")打开文件user.txt*/

fscanf(fp,"%s",name);

fscanf(fp,"%s",pas);/*从文件读取名称和密码字符串*/

printf("%s\n%s",name,pas);

fclose(fp); /*关闭文件*/

return 0;

}

//---------------------------------------------------------------------------

单片机编程中对于数据的读取,写入与输入,输出之间有什么联系???

读取和写入,一般是指存储器

输入和输出,一般是指单片机的IO口

怎样看固态硬盘的读取和写入速度?

。。电脑中下载固态硬盘检测工具软件,安装运行它,会检测你的SSD硬盘读写速度的。如下面的AS SSD Benchmark、Crystaldiskmark、ATTO Disk Benchmarks、SSD-Z等。

mfc 怎么完成对txt文件的读取和写入

我写了一个。

界面一个文本框两个按钮,文本框关联一个CString型变量m_Data,设置属性为Verticalscroll和Wantreturn。

两个按钮对应的读写函数分别如下

voidCFileTxtDlg::OnRead()

{

//TODO:Addyourcontrolnotificationhandlercodehere

CFileDialogfDlg(TRUE);

fDlg.m_ofn.lpstrFilter="TextFiles(*.txt)\0*.txt\0\0";

if(fDlg.DoModal()==IDOK)

{

CStdioFilestdFile;

stdFile.Open(fDlg.GetPathName(),CFile::modeRead|CFile::typeBinary);

DWORDfileLen=stdFile.GetLength();

char*pBuf=newchar[fileLen+1];

pBuf[fileLen]=0;

stdFile.Read(pBuf,fileLen);

UpdateData();

m_Data=pBuf;

UpdateData(FALSE);

deletepBuf;

stdFile.Close();

}

}

voidCFileTxtDlg::OnWrite()

{

//TODO:Addyourcontrolnotificationhandlercodehere

UpdateData();

CFileDialogfDlg(FALSE);

fDlg.m_ofn.lpstrFilter="TextFiles(*.txt)\0*.txt\0\0";

fDlg.m_ofn.lpstrDefExt="txt";

if(IDOK==fDlg.DoModal())

{

CStdioFilestdFile;

stdFile.Open(fDlg.GetPathName(),CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);

stdFile.WriteString(m_Data);

stdFile.Close();

}

}

如要源代码发消息

应用要读取写入或删除存储空间要不要允许

程序运行需要 写入,读取,删除缓存。所以需要存储空间的权限。 程序开发者需要了解哪个手机安装了程序,所以需要手机识别码。

转载请注明出处51数据库 » spire.doc组件读取与写入word .net操作WORD的读取和写入

软件
前端设计
程序设计
Java相关