2017-01-10 8 views
0

Excelのセル文字列をすべて太字のHTMLで太字のタグ付き部分文字列に置き換えてタグを削除する必要があります。私は、同時にタグを削除し、次のようにフォントを設定し、何とか文字列をループする必要があると思います:Excelセルのhtml太字タグを太字にする

xlWorksheet.Cells(1, 2).characters(a, b).font.bold = True 

これは、Windowsフォーム、vb.netまたはC#のではなく、VBAで行う必要があります。 私はInternet Explorerを使用する方法があることを知っていますが、私はむしろそれを使用したくありません。 すべてのリード?

答えて

0

OK。それは自分でしました。太字のタグでのみ動作します。

xlWs.Cells(1, 2).value = StripTags("this <b>should</b> be <b>bold</b>") 
Dim toBold As String = "this <b>should</b> be <b>bold</b>" 
Dim i As Integer = 0 
Dim loopcount As Integer = 0 
While i > -1 
    Dim startTag As Integer = toBold.IndexOf("<b>", i) 
    If startTag = -1 Then Exit While 
    Dim endTag As Integer = toBold.IndexOf("</b>", i) 
    toBold.Remove(startTag, 3) 
    toBold.Remove(endTag, 4) 
    xlWs.Cells(1, 2).characters(startTag + 1 - (loopcount * 7), endTag - startTag - 3).font.bold = True 
    loopcount += 1 
    i = endTag + 1 
End While 


Function StripTags(ByVal html As String) As String 
     Return Regex.Replace(html, "<.*?>", "") 
End Function 
0

あなたがしたいことを達成する方法はたくさんあります。ここでは、あなたがしたいことを達成するための良いサンプルです。

http://vb.net-informations.com/excel-2007/vb.net_excel_update_data_oledb.htm

Imports System.Data 
Public Class Form1 
Private Sub Button1_Click(ByVal sender As System.Object, _ 
      ByVal e As System.EventArgs) Handles Button1.Click 
    Try 
     Dim MyConnection As System.Data.OleDb.OleDbConnection 
     Dim myCommand As New System.Data.OleDb.OleDbCommand 
     Dim sql As String 

     MyConnection = New System.Data.OleDb.OleDbConnection _ 
     ("provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + _ 
     "'c:\testfile.xls';Extended Properties=Excel 8.0;") 

     MyConnection.Open() 
     myCommand.Connection = MyConnection 
     ' This would be where you would find the HTMl or strings that you are trying to change. 
     sql = "Update [Sheet1$] set name = 'New Name' where id=1" 


     myCommand.CommandText = sql 
     myCommand.ExecuteNonQuery() 
     MyConnection.Close() 
    Catch ex As Exception 
     MsgBox(ex.ToString) 
    End Try 
    MsgBox("Updated ") 
End Sub 
End Class 
+0

Excelで太字になるようにt-sqlのテキストを設定するにはどうすればよいですか? – Harri

関連する問題