ネットワーク対応・沙羅の上位版・シンサラ

機能重視型・ご相談はお気軽に 開発:寺院コム

お見積
Lineサポート
遠隔サポート
最近の記事
予約・相談
スマホ版
サラデン
旧沙羅
開発メモなど

※開発メモ—ExcelMap関連

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

関連記事

予約カレンダー
2026年3月
1
×
2
×
3
×
4
×
5
×
6
×
7
×
8
×
9
10
11
12
13
14
×
15
×
16
17
18
19
20
21
×
22
×
23
×
24
×
25
26
27
28
×
29
×
30
31
2026年2月

PAGE TOP