質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
LibreOffice Calc

LibreOffice Calcは、様々なOSで利用可能なオフィススイートであるLibreOfficeに含まれるオープンソースの表計算ソフトです。テンプレートや背景色、枠線といった書式設定の各項目を柔軟で設定することができます。

マクロ

定義された処理手続きに応じて、どのような一連の処理を行うのかを特定させるルールをマクロと呼びます。

Q&A

解決済

1回答

1373閲覧

Libre Officeのcase文

hisatugu

総合スコア2

LibreOffice Calc

LibreOffice Calcは、様々なOSで利用可能なオフィススイートであるLibreOfficeに含まれるオープンソースの表計算ソフトです。テンプレートや背景色、枠線といった書式設定の各項目を柔軟で設定することができます。

マクロ

定義された処理手続きに応じて、どのような一連の処理を行うのかを特定させるルールをマクロと呼びます。

0グッド

0クリップ

投稿2021/05/23 22:39

編集2023/10/17 10:13

前提・実現したいこと

Libre Officeのcase文で、B2の文字列に対し判定しA2に数字を返すのを
A10まで行いたい

試したこと

calc マクロ caseで調べた
あちこち読んでみたがどう書けばいいのかさっぱりわからなかったので、
教えてください

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

y_waiwai

2021/05/23 23:23

なにをやりたいのか意味不明です もちっと詳しく説明しましょう
hisatugu

2021/05/28 22:39

B1が「 彦根」の場合A1に1 B1が「近江八幡」の場合A1に2 B2が「 彦根」の場合A2に1 B2が「近江八幡」の場合A2に2 のようにしたいです
guest

回答1

0

ベストアンサー

Sub Main() Dim mySheet As Object Dim i mySheet = ThisComponent.CurrentController.ActiveSheet For i = 0 To 9 Select Case Right(mySheet.getCellByPosition(1, i).String(), 1) Case "A" To "Z" mySheet.getCellByPosition(0, i).String = 48 Case "坂" mySheet.getCellByPosition(0, i).String = 46 Case Else mySheet.getCellByPosition(0, i).String = 0 End Select Next End Sub

投稿2021/05/27 12:08

jinoji

総合スコア4585

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hisatugu

2021/05/28 22:35

坂を当方の文字列に変更しやってみましたが、A1-A10に0が 代入されてしまいました
jinoji

2021/05/29 03:14 編集

上記サンプルは少し奇をてらって「条件のセルの右端1文字の値で判定」としているので そのような結果になったのだと思います。 普通に「Case "近江八幡"」とかでやる場合は、Select Case文のところを Select Case mySheet.getCellByPosition(1, i).String() としてください。
hisatugu

2021/06/06 23:01

ありがとうございました
hisatugu

2023/10/17 01:13 編集

解決済みではありますが、報告 'マクロの記録から生成 dim document as object dim dispatcher as object rem ---------------------------------------------------------------------- rem get access to the document document = ThisComponent.CurrentController.Frame dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") rem ---------------------------------------------------------------------- dim args1(20) as new com.sun.star.beans.PropertyValue args1(0).Name = "SearchItem.StyleFamily" args1(0).Value = 2 args1(1).Name = "SearchItem.CellType" args1(1).Value = 0 args1(2).Name = "SearchItem.RowDirection" args1(2).Value = true args1(3).Name = "SearchItem.AllTables" args1(3).Value = false args1(4).Name = "SearchItem.SearchFiltered" args1(4).Value = false args1(5).Name = "SearchItem.Backward" args1(5).Value = false args1(6).Name = "SearchItem.Pattern" args1(6).Value = false args1(7).Name = "SearchItem.Content" args1(7).Value = false args1(8).Name = "SearchItem.AsianOptions" args1(8).Value = false args1(9).Name = "SearchItem.AlgorithmType" args1(9).Value = 0 args1(10).Name = "SearchItem.SearchFlags" args1(10).Value = 65536 args1(11).Name = "SearchItem.SearchString" args1(11).Value = "伏見桃山駅前町" args1(12).Name = "SearchItem.ReplaceString" args1(12).Value = "伏見桃山" args1(13).Name = "SearchItem.Locale" args1(13).Value = 255 args1(14).Name = "SearchItem.ChangedChars" args1(14).Value = 2 args1(15).Name = "SearchItem.DeletedChars" args1(15).Value = 2 args1(16).Name = "SearchItem.InsertedChars" args1(16).Value = 2 args1(17).Name = "SearchItem.TransliterateFlags" args1(17).Value = 1280 args1(18).Name = "SearchItem.Command" args1(18).Value = 3 args1(19).Name = "SearchItem.SearchFormatted" args1(19).Value = false args1(20).Name = "SearchItem.AlgorithmType2" args1(20).Value = 1 dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args1()) rem ---------------------------------------------------------------------- dim args0(0) as new com.sun.star.beans.PropertyValue args0(0).Name = "Visible" args0(0).Value = false dispatcher.executeDispatch(document, ".uno:SearchResultsDialog", "", 0, args0()) rem ---------------------------------------------------------------------- dim args2(20) as new com.sun.star.beans.PropertyValue args2(0).Name = "SearchItem.StyleFamily" args2(0).Value = 2 args2(1).Name = "SearchItem.CellType" args2(1).Value = 0 args2(2).Name = "SearchItem.RowDirection" args2(2).Value = true args2(3).Name = "SearchItem.AllTables" args2(3).Value = false args2(4).Name = "SearchItem.SearchFiltered" args2(4).Value = false args2(5).Name = "SearchItem.Backward" args2(5).Value = false args2(6).Name = "SearchItem.Pattern" args2(6).Value = false args2(7).Name = "SearchItem.Content" args2(7).Value = false args2(8).Name = "SearchItem.AsianOptions" args2(8).Value = false args2(9).Name = "SearchItem.AlgorithmType" args2(9).Value = 0 args2(10).Name = "SearchItem.SearchFlags" args2(10).Value = 65536 args2(11).Name = "SearchItem.SearchString" args2(11).Value = "近江八幡駅北口町" args2(12).Name = "SearchItem.ReplaceString" args2(12).Value = "近江八幡" args2(13).Name = "SearchItem.Locale" args2(13).Value = 255 args2(14).Name = "SearchItem.ChangedChars" args2(14).Value = 2 args2(15).Name = "SearchItem.DeletedChars" args2(15).Value = 2 args2(16).Name = "SearchItem.InsertedChars" args2(16).Value = 2 args2(17).Name = "SearchItem.TransliterateFlags" args2(17).Value = 1280 args2(18).Name = "SearchItem.Command" args2(18).Value = 3 args2(19).Name = "SearchItem.SearchFormatted" args2(19).Value = false args2(20).Name = "SearchItem.AlgorithmType2" args2(20).Value = 1 dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args2()) rem ---------------------------------------------------------------------- dim args3(0) as new com.sun.star.beans.PropertyValue args3(0).Name = "Visible" args3(0).Value = false dispatcher.executeDispatch(document, ".uno:SearchResultsDialog", "", 0, args3()) 'case文にて Dim mySheet As Object Dim i mySheet = ThisComponent.CurrentController.ActiveSheet For i = 0 To 70 Select Case mySheet.getCellByPosition(0, i).String() Case "草津駅西口町" mySheet.getCellByPosition(0, i).String = "草津" Case "大津駅前町" mySheet.getCellByPosition(3, i).String = "大津" Case "膳所駅前町" mySheet.getCellByPosition(3, i).String = "膳所" Case Else mySheet.getCellByPosition(2, i).String = 0 Select Case mySheet.getCellByPosition(0, i).String() End Select End Select Next
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問