打开Word文档,依次在菜单栏单击【文件】——【另存为】。
在【另存为】窗口单击“保存类型”,在下拉列表中选择【RTF格式(*.rtf)】,单击【保存】按钮。
打开转换好的RTF文件,接着同样再单击【文件】菜单中的【另存为】命令。
在【保存类型】列表中选择【Word文档(*.doc)】,单击【保存】按钮。
Word文档与RTF的相互转换将保留其格式,如果这种转换没有修复文件,则可以尝试与其他格式相互转换,这将不同程度地保留Word文档的格式。
如果使用这些格式均无法解决本问题,可将文档转换为纯文本格式(.txt),再转换回Word格式。由于纯文本的简单性,有可能修复损坏处,但是Word文档的所有格式设置都将丢失。
打开损坏的Word文档,单击菜单栏的【工具】,打开的菜单单击【选项】命令。
切换到【编辑】标签,将【使用智能段落选择范围】前面的勾去掉,单击【确定】按钮。
选定最后一个段落标记之外的所有内容:先按【Ctrl+End】组合键,然后再按【Ctrl+Shift+Home】。
如何在Excel VBA 中读写word文档 步骤
参考这个:
Sub ExcelToWord() ' 利用Word程序创建文本文件
Dim WordApp As Object
Dim Records As Integer, i As Integer
Dim Region As String, SalesAmt As String, SalesNum As String, strTitle As String
Set WordApp = CreateObject("Word.Application") '创建word对象
Records = Application.CountA(Sheets("sheet1").Range("A:A")) 'A列数据个数
WordApp.Documents.Add '新建文档
'写Title
strTitle = Cells(1, 5)
With WordApp.Selection
.Font.Size = 28
.ParagraphFormat.Alignment = 1 '左对齐0 居中1 右对齐2
.Font.Bold = True
.TypeText Text:=strTitle
.TypeParagraph
End With
'写内容
For i = 1 To Records
'Region = Data.Cells(i, 1).Value '将第一列某行的值赋值给变量
Region = Cells(i, 1)
'SalesNum = Data.Cells(i, 2).Value '获取该行B列数据
SalesNum = Cells(i, 2)
'SalesAmt = Data.Cells(i, 3).Value '获取该行C列数据
SalesAmt = Cells(i, 3)
With WordApp.Selection
.Font.Size = 14 '设置字体字号
.Font.Bold = True '字体粗
.ParagraphFormat.Alignment = 0 '设置对齐
.TypeText Text:=Region & SalesNum
.TypeParagraph
.Font.Size = 12 '设置字体
.ParagraphFormat.Alignment = 0 '设置对齐
.Font.Bold = False '字体不加粗
.TypeText Text:=vbTab & SalesAmt
.TypeParagraph '回车
.TypeParagraph '回车
End With
Next i
WordApp.ActiveDocument.SaveAs Filename:="AAA" '保存文件
WordApp.Quit '退出程序
Set WordApp = Nothing '清空
MsgBox "文件保存在我的文档底下的AAA文件"
End Sub
如何利用java实现Word和Excel文件的读写
您可以使用JAVA2Word插件操作word;
您可以使用POI插件操作EXcel。
如果您不会,请来电或者QQ咨询我,我将给你例子,谢谢
参考资料:在CSDN索索“zjqwll”,找到zjqwll CSDN下载频道
如何在excel vba 中读写word文档 步骤
Subtext()DimwdAsNewWord.Application
Setwd=CreateObject("word.application")
Withwd
.Visible=True
.Documents.Add
EndWith
ActiveDocument.Range.text="123456789"
EndSub
以上代码在excel模块当中写入,新建Word,并向其中写入字符"123456789"
注意:需要在引用中勾选word 14.0 如图
如何在Excel VBA 中读写word文档 步骤
1. 库的配置
在默认情况下,新创建的excel vba中不支持定义word对象。
所以需要先引入word库,操作步骤如下:
1.1 打开excel vba 界面
1.2 选中其中的一个Module
1.3 选择菜单, Tools --> References
在打开的对话框中选择类似 "Microsoft Word 14.0 Object Library".
1.4 点击OK保存配置。
2. 打开文档
Set wordApplication = CreateObject("Word.Application")
wordApplication.Visible = False
Dim hasOpenDoc As Boolean
hasOpenDoc = IsOpen(filePath) ' is a self-defined function to check file is opend
If hasOpenDoc = True then
Set wordDoc = GetObject(filePath)
End if
If hasOpenDoc = False Then
Set wordDoc = wordApplication.Documents.Open(filePath)
End if
wordDoc.Active
With wordApplication
Dim aParagraph As Word.Paragraph
For Each aParagraph In wordDoc.Paragraphs
' do some thing to every paragraph.
Next aParagraph
End with
wordDoc.Close
Set wordDoc = nothing
' 如下这段代码引用某位牛人的,非常感谢他。由于路径丢失,不能给出链接, 抱歉
' 如下的找寻方式,能够正确的找出文件是否被打开
Function IsOpen(fileName As String) As Boolean
IsOpen = False
Dim findFile As Integer
findFile = FreeFile()
On Error GoTo ErrOpen
Open fileName For Binary Lock Read Write As findFile
Close findFile
Exit Function
ErrOpen:
If Err.Number <> 70 Then
Msg = "Error # " & Str(Err.Number) & "was generated by " & Err.Source & Chr(13) & Err.Description
MsgBox Msg, "Error", Err.HelpFile, Err.HelpContext
Else
IsOpen = True
End If
End Function
如何在Excel VBA 中读写word文档 步骤
所以需要先引入word库,操作步骤如下:
1.1 打开excel vba 界面
1.2 选中其中的一个Module
1.3 选择菜单, Tools --> References
在打开的对话框中选择类似 "Microsoft Word 14.0 Object Library".
1.4 点击OK保存配置。
2. 打开文档
Set wordApplication = CreateObject("Word.Application")
wordApplication.Visible = False
Dim hasOpenDoc As Boolean
hasOpenDoc = IsOpen(filePath) ' is a self-defined function to check file is opend
If hasOpenDoc = True then
Set wordDoc = GetObject(filePath)
End if
If hasOpenDoc = False Then
Set wordDoc = wordApplication.Documents.Open(filePath)
End if
wordDoc.Active
With wordApplication
Dim aParagraph As Word.Paragraph
For Each aParagraph In wordDoc.Paragraphs
' do some thing to every paragraph.
Next aParagraph
End with
wordDoc.Close
Set wordDoc = nothing
' 如下这段代码引用某位牛人的,非常感谢他。由于路径丢失,不能给出链接, 抱歉
' 如下的找寻方式,能够正确的找出文件是否被打开
Function IsOpen(fileName As String) As Boolean
IsOpen = False
Dim findFile As Integer
findFile = FreeFile()
On Error GoTo ErrOpen
Open fileName For Binary Lock Read Write As findFile
Close findFile
Exit Function
ErrOpen:
If Err.Number <> 70 Then
Msg = "Error # " & Str(Err.Number) & "was generated by " & Err.Source & Chr(13) & Err.Description
MsgBox Msg, "Error", Err.HelpFile, Err.HelpContext
Else
IsOpen = True
End If
End Function
delphi读取WORD文档每一页的内容
uses ComObj,WordXp;
var wordapp, WordDoc, PageRange: Variant;
sContext: string;
i, nPageCounts, nStart, nEnd : Integer;
begin
wordapp := CreateOleObject('Word.Application');
try
wordapp.Visible := True;
if dlgOpen1.Execute = False then Exit;
WordDoc := wordapp.Documents.Open(dlgOPen1.FileName);
//文档总页数
nPageCounts := wordapp.Selection.Information[wdNumberOfPagesInDocument];
//如果只有一页 那么全选就OK了
if nPageCounts = 1 then
begin
wordapp.Selection.WholeStory;
mmo1.Lines.Add('=============第'+IntToStr(nPageCounts)+'页内容:===================');
mmo1.Lines.Add(wordapp.Selection.Text);
Exit;
end;
nStart := -1;
nEnd := -1;
//循环获取文档页中的内容
for i := 1 to nPageCounts do
begin
//定位到第i页
PageRange := wordapp.Selection.GoTo(wdGoToPage, wdGoToNext, IntToStr(i));
//如果第i页是最后一页 那么直接将光标移动到最后 并输出内容
if i = nPageCounts then
begin
wordapp.Selection.EndKey(wdStory,wdExtend);
sContext := WordApp.Selection.Range.Text;
mmo1.Lines.Add('=============第'+IntToStr(i)+'页内容:===================');
mmo1.Lines.Add(sContext);
Exit;
end;
//取第i页的页首位置作为开始位置
nStart := wordapp.Selection.Start;
//定位到i+1页
PageRange := wordapp.Selection.GoTo(wdGoToPage, wdGoToNext, IntToStr(i+1));
//取第i+1页的页首位置作为结束位置
nEnd := wordapp.Selection.Start;
//根据开始位置和结束位置确定文档选中的内容(第i页的内容)
WordDoc.Range(nStart,nEnd).Select;
sContext := WordDoc.Range.Text;
//输出内容
mmo1.Lines.Add('=============第'+IntToStr(i)+'页内容:===================');
mmo1.Lines.Add(sContext);
nStart := -1;
nEnd := -1;
end;
finally
wordapp.Quit;
end;
end;
昨天没有测试好 这个应该没有问题了吧 试一下吧
转载请注明出处51数据库 » word文件读写 QT读写WORD文档该怎么处理
威海百变大咖
