GrapeCity.Documents.Excel が非常に便利だったので覚え書き
マップのテキストボックスに背景色とハイパーリンクを付けるImports GrapeCity.Documents.Excel
Imports GrapeCity.Documents.Excel.Drawing
Imports System.Drawing
Module Module1
Sub Main()
' Excelワークブックを作成
Dim workbook As New Workbook()
' 既存のExcelファイルを開く
workbook.Open("f:\エクセルテスト\maptest.xlsx")
' アクティブシートを取得
Dim sheet As IWorksheet = workbook.Worksheets(0)
' すべての図形を取得
Dim shapes = sheet.Shapes
' 特定のテキストボックスの名前を指定
Dim targetBochiKukaku As String = "あ1"
' テキストボックスを検索⇒テキストボックスのNameで検索
For Each shape As IShape In sheet.Shapes
If shape.Name = targetBochiKukaku Then
' 背景色を赤に設定
shape.Fill.Solid()
shape.Fill.Color.RGB = Color.Red
'ハイパーリンクを設定
' If shape.AutoShapeType = AutoShapeType.TextBox Then
Dim hyperlinkUrl As String = $"https://xxx.com/?xxx={shape.Name}"
sheet.Hyperlinks.Add(shape, hyperlinkUrl)
' End If
End If
Next
' PDFとして保存
Dim pdfFilePath As String = "f:\エクセルテスト\output.pdf"
workbook.Save(pdfFilePath, SaveFileFormat.Pdf)
' PDFファイルを開く
Process.Start(New ProcessStartInfo(pdfFilePath) With {.UseShellExecute = True})
'Console.WriteLine("テキストボックスの背景色を赤に変更して保存しました。")
End Sub
End ModuleテキストボックスのNameではなく、中身(TextRange.text)で検索
'' テキストボックスを検索⇒テキストボックスの入力されている値を検索
'For Each shape As IShape In shapes
' If shape.TextFrame IsNot Nothing Then
' Dim textContent As String = shape.TextFrame.TextRange.Text
' If textContent.Contains(targetBochiKukaku) Then
' ' 背景色を赤に設定
' shape.Fill.Solid()
' shape.Fill.Color.RGB = Color.Red
' End If
' End If
'Next
Imports GrapeCity.Documents.Excel
Imports GrapeCity.Documents.Excel.Drawing
Imports System.Drawing
Module Module1
Sub Main()
' Excelワークブックを作成
Dim workbook As New Workbook()
' 既存のExcelファイルを開く
workbook.Open("f:\エクセルテスト\maptest.xlsx")
' アクティブシートを取得
Dim sheet As IWorksheet = workbook.Worksheets(0)
' すべての図形を取得
Dim shapes = sheet.Shapes
' 特定のテキストボックスの名前を指定
Dim targetBochiKukaku As String = "あ1"
' テキストボックスを検索⇒テキストボックスのNameで検索
For Each shape As IShape In sheet.Shapes
If shape.Name = targetBochiKukaku Then
' 背景色を赤に設定
shape.Fill.Solid()
shape.Fill.Color.RGB = Color.Red
'ハイパーリンクを設定
' If shape.AutoShapeType = AutoShapeType.TextBox Then
Dim hyperlinkUrl As String = $"https://xxx.com/?xxx={shape.Name}"
sheet.Hyperlinks.Add(shape, hyperlinkUrl)
' End If
End If
Next
' PDFとして保存
Dim pdfFilePath As String = "f:\エクセルテスト\output.pdf"
workbook.Save(pdfFilePath, SaveFileFormat.Pdf)
' PDFファイルを開く
Process.Start(New ProcessStartInfo(pdfFilePath) With {.UseShellExecute = True})
'Console.WriteLine("テキストボックスの背景色を赤に変更して保存しました。")
End Sub
End ModuleテキストボックスのNameではなく、中身(TextRange.text)で検索
'' テキストボックスを検索⇒テキストボックスの入力されている値を検索 'For Each shape As IShape In shapes ' If shape.TextFrame IsNot Nothing Then ' Dim textContent As String = shape.TextFrame.TextRange.Text ' If textContent.Contains(targetBochiKukaku) Then ' ' 背景色を赤に設定 ' shape.Fill.Solid() ' shape.Fill.Color.RGB = Color.Red ' End If ' End If 'Next













