オープンオフィスのドキュメントをマイクロソフトオフィスのファイルに変換するとき、いちいちファイルに開けて、名前をつけて保存をするのが面倒なので、マクロを作りました。
使い方は下のコードを参照してください。
使い方は下のコードを参照してください。
' OpenOfficeドキュメントをPDFに変換するマクロ
'
' バッチ処理用
'
' 使用例 : Unix の場合
'
' $ for i in `find . -type f -name *.doc -exec realpath {} \; `; \
' do ooffice -invisible macro:///Standard.ConvertToMacros.ConvertToPDF\($i\); \
' done
'
'
' @param strFile 入力ファイル名
'
' @author Osachan
' @version 1.0.0
' @since 1.0.0
Sub ConvertToPDF(strFile as string)
Dim oDoc as Object
Dim strFilterSubName as String
strUrl = ConvertToUrl( strFile )
oDoc = StarDesktop.loadComponentFromURL( strUrl, "_blank", 0, array(MakePropertyValue("Hidden",true)))
If not IsNull(oDoc) Then
strFilterSubName = ""
' select appropriate filter
If oDoc.SupportsService("com.sun.star.presentation.PresentationDocument") Then
strFilterSubName = "impress_pdf_Export"
ElseIf oDoc.SupportsService("com.sun.star.sheet.SpreadsheetDocument") Then
strFilterSubName = "calc_pdf_Export"
ElseIf oDoc.SupportsService("com.sun.star.text.WebDocument") Then
strFilterSubName = "writer_web_pdf_Export"
ElseIf oDoc.SupportsService("com.sun.star.text.GlobalDocument") Then
strFilterSubName = "writer_globaldocument_pdf_Export"
ElseIf oDoc.SupportsService("com.sun.star.text.TextDocument") Then
strFilterSubName = "writer_pdf_Export"
ElseIf oDoc.SupportsService("com.sun.star.drawing.DrawingDocument") Then
strFilterSubName = "draw_pdf_Export"
ElseIf oDoc.SupportsService("com.sun.star.formula.FormulaProperties") Then
strFilterSubName = "math_pdf_Export"
ElseIf oDoc.SupportsService("com.sun.star.chart.ChartDocument") Then
strFilterSubName = "chart_pdf_Export"
Else
'
EndIf
EndIf
If Len(strFilterSubName) > 0 Then
oDoc.storeToUrl( ConvertToUrl( strFile & ".pdf" ), array(MakePropertyValue("FilterName", strFilterSubName ),MakePropertyValue("CompressMode", "1" )))
EndIf
oDoc.close(True)
End Sub
' Microsoft OfficeのドキュメントをOpen Office用ドキュメントに変換するマクロ
'
' バッチ処理用
'
' 使用例 : Unix の場合
'
' $ for i in `find . -type f -name *.doc -exec realpath {} \; `; \
' do ooffice -invisible macro:///Standard.ConvertToMacros.ConvertToOOO\($i\); \
' done
'
'
' @param strFile 入力ファイル名
'
' @author Osachan
' @version 1.0.0
' @since 1.0.0
Sub ConvertToOOO( strFile )
Dim oDoc as Object
Dim strFileExt as String
Dim strURL as String
strUrl = ConvertToUrl( strFile )
oDoc = StarDesktop.loadComponentFromURL( strUrl, "_blank", 0, array(MakePropertyValue("Hidden",true)))
If not IsNull(oDoc) Then
strFileExt = ""
' select appropriate filter
If oDoc.SupportsService("com.sun.star.presentation.PresentationDocument") Then
strFileExt = "odp"
ElseIf oDoc.SupportsService("com.sun.star.sheet.SpreadsheetDocument") Then
strFileExt = "ods"
ElseIf oDoc.SupportsService("com.sun.star.text.GlobalDocument") Then
strFileExt = "odt"
ElseIf oDoc.SupportsService("com.sun.star.text.TextDocument") Then
strFileExt = "odt"
Else
'
EndIf
EndIf
If Len(strFileExt) > 0 Then
strURL = ConvertToURL( Left( strFile, Len( strFile ) - 3 ) & strFileExt )
oDoc.storeAsURL( strURL, Array() )
EndIf
oDoc.close( True )
End Sub
' Open Office用ドキュメントをMicrosoft Officeのドキュメントに変換するマクロ
'
' バッチ処理用
'
' 使用例 : Unix の場合
'
' $ for i in `find . -type f -name *.ods -exec realpath {} \; `; \
' do ooffice -invisible macro:///Standard.ConvertToMacros.ConvertToMS\($i\); \
' done
'
'
' @param strFile 入力ファイル名
'
' @author Osachan
' @version 1.0.0
' @since 1.0.0
Sub ConvertToMS( strFile )
Dim oDoc as Object
Dim strFileExt as String
Dim strURL as String
Dim strMsExtType as String
strUrl = ConvertToUrl( strFile )
oDoc = StarDesktop.loadComponentFromURL( strUrl, "_blank", 0, array(MakePropertyValue("Hidden",true)))
If not IsNull(oDoc) Then
strFilterSubName = ""
' select appropriate filter
If oDoc.SupportsService("com.sun.star.presentation.PresentationDocument") Then
strFileExt = "ppt"
strMsExtType = "MS Powerpoint 97"
ElseIf oDoc.SupportsService("com.sun.star.sheet.SpreadsheetDocument") Then
strFileExt = "xls"
strMsExtType = "MS Excel 97"
ElseIf oDoc.SupportsService("com.sun.star.text.GlobalDocument") Then
strFileExt = "doc"
strMsExtType = "MS Word 97"
ElseIf oDoc.SupportsService("com.sun.star.text.TextDocument") Then
strFileExt = "doc"
strMsExtType = "MS Word 97"
Else
'
EndIf
EndIf
If Len(strFileExt) > 0 Then
strURL = ConvertToURL( Left( strFile, Len( strFile ) - 3 ) & strFileExt )
oDoc.storeAsURL( strURL, Array(_
MakePropertyValue( "FilterName", strMsExtType ),)
EndIf
oDoc.close( True )
End Sub
Function MakePropertyValue( Optional strName As String, Optional strValue ) As com.sun.star.beans.PropertyValue
oPropertyValue = createUnoStruct( "com.sun.star.beans.PropertyValue" )
If Not IsMissing( strName ) Then
oPropertyValue.Name = strName
EndIf
If Not IsMissing( strValue ) Then
oPropertyValue.Value = strValue
EndIf
MakePropertyValue() = oPropertyValue
End Function
