我正在使用VB 2010上的DevExpress 2012控件。我有一个richtext编辑控件,可用作Microsoft Word替换。我正在加载包含标题的Word文档。我需要清除该标头并使用新数据重新创建它。我知道如何在新文档中插入包含数据的新标题,但我不知道如何清除现有标题。我找不到办法做到这一点。以下代码无效。任何想法?
Dim headerSection As Section = devWordControl.Document.Sections(0)
Dim subDoc As SubDocument = headerSection.BeginUpdateHeader(HeaderFooterType.First)
If headerSection.Margins.Left <> 170 Then
headerSection.Margins.Left = 170
End If
If headerSection.Margins.Right <> 130 Then
headerSection.Margins.Right = 130
End If
subDoc.SelectAll()
subDoc.Delete(subDoc.Range)
headerSection.EndUpdateHeader(subDoc)
答案 0 :(得分:1)
我相信你可以使用以下代码片段,对我来说很好用:
Sub InsertHeader_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs)
Dim firstSection As Section = richEditControl1.Document.Sections(0)
Dim hDoc As SubDocument = firstSection.BeginUpdateHeader()
hDoc.InsertText(hDoc.CreatePosition(0), "Header")
firstSection.EndUpdateHeader(hDoc)
End Sub
Sub ChangeHeader_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs)
Dim firstSection As Section = richEditControl1.Document.Sections(0)
Dim hDoc As SubDocument = firstSection.BeginUpdateHeader()
hDoc.Delete(hDoc.Range)
hDoc.InsertText(hDoc.CreatePosition(0), "New Header")
firstSection.EndUpdateHeader(hDoc)
End Sub