问题一,批量导入WORD文件里的表格时,有一单元格是简介,有换行,导进来成为了一个段落,如何解决?问题二,导出去后,首行缩进两个字符,如何实现?
麻烦老师解答,谢谢
已经解决,感谢!
[此贴子已经被作者于2023/10/24 10:14:57编辑过]
请把word文件发上来测试一下。导入导出使用了什么代码?
Dim directory As String = "C:\Users\Administrator\Desktop\志愿表采集\"
Dim app As New MSWord.Application
Try
For Each File As String In FileSys.GetFiles(directory)
Dim fs As String = FileSys.GetName(file)
If fs.Contains(".docx") OrElse fs.Contains(".doc") Then
Dim dr As Row = Tables("表A").AddNew
Dim fileName = directory & fs
Dim doc = app.Documents.Open(fileName)
Dim t = doc.Tables(1)
Dim n1() As String = {1, 1, 1, 1, 2, 2, 2, 4, 4, 4, 5} '学生姓名
Dim n2() As String = {2, 4, 6, 8, 2, 4, 6, 2, 4, 6, 2} '学生姓名
For i As Integer = 0 To n1.Length - 1
Dim text = t.Cell(n1(i), n2(i)).Range.Text.ToString()
text = text.Substring(0, text.Length - 2)
text = text.Replace(" ", "")
text = text.Replace("老师", "")
dr("第" & i + 1 & "列") = text
Next
dr.Save
End If
Next
Catch ex As exception
msgbox(ex.message)
Finally
app.Quit
上述是导入表,简介通过代码导入到备注字段里,没有换行符号。

此主题相关图片如下:微信图片_20231024100438.png
文档里只有回车,没有换行加上
text = text.Replace(vbcr, vbcrlf)