Reputation: 11441
The RDCOMclient
package can be used to connect to COM objects on Windows. In the MSDN reference many enumerations exist (e.g. wdColorBlue
for blue, see here) which correspond to a value. These can be directly used e.g. in VBA code.
How can I work with enumeration objects using RDCOMClient? Is there e.g. a way to retrieve the corresponding value for an enumeration from within R? There is a function EnumValue
but I do not see how to use it for this purpose.
A small example
The following codes creates a new Word document and writes some text in it. The paragraph is changed to right alignment. Here the integer 2
is used which corresponds to the enumeration wdAlignParagraphRight
. I would like to be able to use e.g. the string "wdAlignParagraphRight"
instead of the value 2
. Is there a way to do that using RDCOMclient
?
x <- COMCreate("Word.Application") # create application
x[["visible"]] <- TRUE
x[["Documents"]]$Add()
x[["Selection"]]$TypeText("hello")
p <- x[["ActiveDocument"]][["Paragraphs"]]$Item(1)
p[["Alignment"]] <- 2
Upvotes: 9
Views: 555
Reputation: 2233
You can use the variable wdConst that is in the R package DescTools to achieve this :
library(DescTools)
library(RDCOMClient)
x <- COMCreate("Word.Application") # create application
x[["visible"]] <- TRUE
x[["Documents"]]$Add()
x[["Selection"]]$TypeText("hello")
p <- x[["ActiveDocument"]][["Paragraphs"]]$Item(1)
p[["Alignment"]] <- wdConst$wdAlignParagraphRight
names(wdConst)
[1] "wd100Words" "wd10Percent"
[3] "wd10Sentences" "wd20Sentences"
[5] "wd24HourClock" "wd25Percent"
[7] "wd500Words" "wd50Percent"
[9] "wd70" "wd70FE"
[11] "wd75Percent" "wd80"
[13] "wdActiveEndAdjustedPageNumber" "wdActiveEndPageNumber"
[15] "wdActiveEndSectionNumber" "wdAddress1"
[17] "wdAddress2" "wdAddress3"
[19] "wdAdjective" "wdAdjustFirstColumn"
[21] "wdAdjustNone" "wdAdjustProportional"
[23] "wdAdjustSameWidth" "wdAdverb"
[25] "wdAfrikaans" "wdAlbanian"
[27] "wdAlertsAll" "wdAlertsMessageBox"
[29] "wdAlertsNone" "wdAlignPageNumberCenter"
[31] "wdAlignPageNumberInside" "wdAlignPageNumberLeft"
[33] "wdAlignPageNumberOutside" "wdAlignPageNumberRight"
[35] "wdAlignParagraphCenter" "wdAlignParagraphDistribute"
[37] "wdAlignParagraphJustify" "wdAlignParagraphJustifyHi"
[39] "wdAlignParagraphJustifyLow" "wdAlignParagraphJustifyMed"
[41] "wdAlignParagraphLeft" "wdAlignParagraphRight"
[43] "wdAlignParagraphThaiJustify" "wdAlignRowCenter"
[45] "wdAlignRowLeft" "wdAlignRowRight"
[47] "wdAlignTabBar" "wdAlignTabCenter"
[49] "wdAlignTabDecimal" "wdAlignTabLeft"
[51] "wdAlignTablesRowByRow" "wdAlignTabList"
[53] "wdAlignTabRight" "wdAlignVerticalBottom"
[55] "wdAlignVerticalCenter" "wdAlignVerticalJustify"
[57] "wdAlignVerticalTop" "wdAllAtOnce"
[59] "wdAllowOnlyComments" "wdAllowOnlyFormFields"
[61] "wdAllowOnlyReading" "wdAllowOnlyRevisions"
[63] "wdAlwaysConvert" "wdAmharic"
[65] "wdAnagram" "wdAnimationBlinkingBackground"
[67] "wdAnimationLasVegasLights" "wdAnimationMarchingBlackAnts"
[69] "wdAnimationMarchingRedAnts" "wdAnimationNone"
[71] "wdAnimationShimmer" "wdAnimationSparkleText"
[73] "wdApplyBreakingRules" "wdArabic"
[75] "wdArabicAlgeria" "wdArabicBahrain"
[77] "wdArabicEgypt" "wdArabicIraq"
[79] "wdArabicJordan" "wdArabicKuwait"
[81] "wdArabicLebanon" "wdArabicLibya"
[83] "wdArabicMorocco" "wdArabicOman"
[85] "wdArabicQatar" "wdArabicSyria"
[87] "wdArabicTunisia" "wdArabicUAE"
[89] "wdArabicYemen" "wdArgentina"
[91] "wdArmenian" "wdArtApples"
[93] "wdArtArchedScallops" "wdArtBabyPacifier"
[95] "wdArtBabyRattle" "wdArtBalloons3Colors"
[97] "wdArtBalloonsHotAir" "wdArtBasicBlackDashes"
[99] "wdArtBasicBlackDots" "wdArtBasicBlackSquares"
[101] "wdArtBasicThinLines" "wdArtBasicWhiteDashes"
[103] "wdArtBasicWhiteDots" "wdArtBasicWhiteSquares"
[105] "wdArtBasicWideInline" "wdArtBasicWideMidline"
[107] "wdArtBasicWideOutline" "wdArtBats"
[109] "wdArtBirds" "wdArtBirdsFlight"
[111] "wdArtCabins" "wdArtCakeSlice"
[113] "wdArtCandyCorn" "wdArtCelticKnotwork"
[115] "wdArtCertificateBanner" "wdArtChainLink"
[117] "wdArtChampagneBottle" "wdArtCheckedBarBlack"
[119] "wdArtCheckedBarColor" "wdArtCheckered"
[121] "wdArtChristmasTree" "wdArtCirclesLines"
[123] "wdArtCirclesRectangles" "wdArtClassicalWave"
[125] "wdArtClocks" "wdArtCompass"
[127] "wdArtConfetti" "wdArtConfettiGrays"
[129] "wdArtConfettiOutline" "wdArtConfettiStreamers"
[131] "wdArtConfettiWhite" "wdArtCornerTriangles"
[133] "wdArtCouponCutoutDashes" "wdArtCouponCutoutDots"
[135] "wdArtCrazyMaze" "wdArtCreaturesButterfly"
[137] "wdArtCreaturesFish" "wdArtCreaturesInsects"
[139] "wdArtCreaturesLadyBug" "wdArtCrossStitch"
[141] "wdArtCup" "wdArtDecoArch"
[143] "wdArtDecoArchColor" "wdArtDecoBlocks"
[145] "wdArtDiamondsGray" "wdArtDoubleD"
[147] "wdArtDoubleDiamonds" "wdArtEarth1"
[149] "wdArtEarth2" "wdArtEclipsingSquares1"
[151] "wdArtEclipsingSquares2" "wdArtEggsBlack"
[153] "wdArtFans" "wdArtFilm"
[155] "wdArtFirecrackers" "wdArtFlowersBlockPrint"
[157] "wdArtFlowersDaisies" "wdArtFlowersModern1"
[159] "wdArtFlowersModern2" "wdArtFlowersPansy"
[161] "wdArtFlowersRedRose" "wdArtFlowersRoses"
[163] "wdArtFlowersTeacup" "wdArtFlowersTiny"
[165] "wdArtGems" "wdArtGingerbreadMan"
[167] "wdArtGradient" "wdArtHandmade1"
[169] "wdArtHandmade2" "wdArtHeartBalloon"
[171] "wdArtHeartGray" "wdArtHearts"
[173] "wdArtHeebieJeebies" "wdArtHolly"
[175] "wdArtHouseFunky" "wdArtHypnotic"
[177] "wdArtIceCreamCones" "wdArtLightBulb"
[179] "wdArtLightning1" "wdArtLightning2"
[181] "wdArtMapleLeaf" "wdArtMapleMuffins"
[183] "wdArtMapPins" "wdArtMarquee"
[185] "wdArtMarqueeToothed" "wdArtMoons"
[187] "wdArtMosaic" "wdArtMusicNotes"
[189] "wdArtNorthwest" "wdArtOvals"
[191] "wdArtPackages" "wdArtPalmsBlack"
[193] "wdArtPalmsColor" "wdArtPaperClips"
[195] "wdArtPapyrus" "wdArtPartyFavor"
[197] "wdArtPartyGlass" "wdArtPencils"
[199] "wdArtPeople" "wdArtPeopleHats"
[201] "wdArtPeopleWaving" "wdArtPoinsettias"
[203] "wdArtPostageStamp" "wdArtPumpkin1"
[205] "wdArtPushPinNote1" "wdArtPushPinNote2"
[207] "wdArtPyramids" "wdArtPyramidsAbove"
[209] "wdArtQuadrants" "wdArtRings"
[211] "wdArtSafari" "wdArtSawtooth"
[213] "wdArtSawtoothGray" "wdArtScaredCat"
[215] "wdArtSeattle" "wdArtShadowedSquares"
[217] "wdArtSharksTeeth" "wdArtShorebirdTracks"
[219] "wdArtSkyrocket" "wdArtSnowflakeFancy"
[221] "wdArtSnowflakes" "wdArtSombrero"
[223] "wdArtSouthwest" "wdArtStars"
[225] "wdArtStars3D" "wdArtStarsBlack"
[227] "wdArtStarsShadowed" "wdArtStarsTop"
[229] "wdArtSun" "wdArtSwirligig"
[231] "wdArtTornPaper" "wdArtTornPaperBlack"
[233] "wdArtTrees" "wdArtTriangleParty"
[235] "wdArtTriangles" "wdArtTribal1"
[237] "wdArtTribal2" "wdArtTribal3"
[239] "wdArtTribal4" "wdArtTribal5"
[241] "wdArtTribal6" "wdArtTwistedLines1"
[243] "wdArtTwistedLines2" "wdArtVine"
[245] "wdArtWaveline" "wdArtWeavingAngles"
[247] "wdArtWeavingBraid" "wdArtWeavingRibbon"
[249] "wdArtWeavingStrips" "wdArtWhiteFlowers"
[251] "wdArtWoodwork" "wdArtXIllusions"
[253] "wdArtZanyTriangles" "wdArtZigZag"
[255] "wdArtZigZagStitch" "wdAskToConvert"
[257] "wdAskToNotConvert" "wdAssamese"
[259] "wdAtEndOfRowMarker" "wdAttachedTemplate"
[261] "wdAuto" "wdAutoClose"
[263] "wdAutoDetectHighAnsiFarEast" "wdAutoExec"
[265] "wdAutoExit" "wdAutoFitContent"
[267] "wdAutoFitFixed" "wdAutoFitWindow"
[269] "wdAutomaticUpdate" "wdAutoNew"
[271] "wdAutoOpen" "wdAutoPosition"
[273] "wdAutoRecoverPath" "wdAutospaceLikeWW7"
[275] "wdAutoSync" "wdAutoVersionOff"
[277] "wdAutoVersionOnClose" "wdAzeriCyrillic"
[279] "wdAzeriLatin" "wdBackward"
[281] "wdBalloonPrintOrientationAuto" "wdBalloonPrintOrientationForceLandscape"
[283] "wdBalloonPrintOrientationPreserve" "wdBalloonRevisions"
[285] "wdBalloonWidthPercent" "wdBalloonWidthPoints"
[287] "wdBaselineAlignAuto" "wdBaselineAlignBaseline"
[289] "wdBaselineAlignCenter" "wdBaselineAlignFarEast50"
[291] "wdBaselineAlignTop" "wdBasque"
[293] "wdBelgianDutch" "wdBelgianFrench"
[295] "wdBeneathText" "wdBengali"
[297] "wdBlack" "wdBlue"
[299] "wdBorderArtPath" "wdBorderBottom"
[301] "wdBorderDiagonalDown" "wdBorderDiagonalUp"
[303] "wdBorderDistanceFromPageEdge" "wdBorderDistanceFromText"
[305] "wdBorderHorizontal" "wdBorderLeft"
[307] "wdBorderRight" "wdBorderTop"
[309] "wdBorderVertical" "wdBoth"
[311] "wdBottomOfPage" "wdBrazil"
[313] "wdBrazilianPortuguese" "wdBrightGreen"
[315] "wdBrowseComment" "wdBrowseEdit"
[317] "wdBrowseEndnote" "wdBrowseField"
[319] "wdBrowseFind" "wdBrowseFootnote"
[321] "wdBrowseGoTo" "wdBrowseGraphic"
[323] "wdBrowseHeading" "wdBrowsePage"
[325] "wdBrowserLevelMicrosoftInternetExplorer5" "wdBrowserLevelMicrosoftInternetExplorer6"
[327] "wdBrowserLevelV4" "wdBrowseSection"
[329] "wdBrowseTable" "wdBulgarian"
[331] "wdBulletGallery" "wdBurmese"
[333] "wdBusinessFax" "wdBusinessPhone"
[335] "wdByAuthor" "wdByelorussian"
[337] "wdCalculationText" "wdCalendarArabic"
[339] "wdCalendarChina" "wdCalendarHebrew"
[341] "wdCalendarJapan" "wdCalendarKorean"
[343] "wdCalendarSakaEra" "wdCalendarThai"
[345] "wdCalendarTypeBidi" "wdCalendarTypeGregorian"
[347] "wdCalendarWestern" "wdCanada"
[349] "wdCancelDisabled" "wdCancelInterrupt"
[351] "wdCancelPublisher" "wdCapsLock"
[353] "wdCaptionEquation" "wdCaptionFigure"
[355] "wdCaptionNumberStyleArabic" "wdCaptionNumberStyleArabicFullWidth"
[357] "wdCaptionNumberStyleArabicLetter1" "wdCaptionNumberStyleArabicLetter2"
[359] "wdCaptionNumberStyleBidiLetter1" "wdCaptionNumberStyleBidiLetter2"
[361] "wdCaptionNumberStyleChosung" "wdCaptionNumberStyleGanada"
[363] "wdCaptionNumberStyleHanjaRead" "wdCaptionNumberStyleHanjaReadDigit"
[365] "wdCaptionNumberStyleHebrewLetter1" "wdCaptionNumberStyleHebrewLetter2"
[367] "wdCaptionNumberStyleHindiArabic" "wdCaptionNumberStyleHindiCardinalText"
[369] "wdCaptionNumberStyleHindiLetter1" "wdCaptionNumberStyleHindiLetter2"
[371] "wdCaptionNumberStyleKanji" "wdCaptionNumberStyleKanjiDigit"
[373] "wdCaptionNumberStyleKanjiTraditional" "wdCaptionNumberStyleLowercaseLetter"
[375] "wdCaptionNumberStyleLowercaseRoman" "wdCaptionNumberStyleNumberInCircle"
[377] "wdCaptionNumberStyleSimpChinNum2" "wdCaptionNumberStyleSimpChinNum3"
[379] "wdCaptionNumberStyleThaiArabic" "wdCaptionNumberStyleThaiCardinalText"
[381] "wdCaptionNumberStyleThaiLetter" "wdCaptionNumberStyleTradChinNum2"
[383] "wdCaptionNumberStyleTradChinNum3" "wdCaptionNumberStyleUppercaseLetter"
[385] "wdCaptionNumberStyleUppercaseRoman" "wdCaptionNumberStyleVietCardinalText"
[387] "wdCaptionNumberStyleZodiac1" "wdCaptionNumberStyleZodiac2"
[389] "wdCaptionPositionAbove" "wdCaptionPositionBelow"
[391] "wdCaptionTable" "wdCatalan"
[393] "wdCatalog" "wdCell"
[395] "wdCellAlignVerticalBottom" "wdCellAlignVerticalCenter"
[397] "wdCellAlignVerticalTop" "wdCenterClockwise"
[399] "wdCenterLandscape" "wdCenterPortrait"
[401] "wdCentimeters" "wdChangeAttributes"
[403] "wdCharacter" "wdCharacterFormatting"
[405] "wdChart" "wdChartLinked"
[407] "wdChartPicture" "wdCherokee"
[409] "wdChile" "wdChina"
[411] "wdChineseHongKong" "wdChineseHongKongSAR"
[413] "wdChineseMacao" "wdChineseMacaoSAR"
[415] "wdChineseSingapore" "wdCity"
[417] "wdCollapseEnd" "wdCollapseStart"
[419] "wdColorAqua" "wdColorAutomatic"
[421] "wdColorBlack" "wdColorBlue"
[423] "wdColorBlueGray" "wdColorBrightGreen"
[425] "wdColorBrown" "wdColorDarkBlue"
[427] "wdColorDarkGreen" "wdColorDarkRed"
[429] "wdColorDarkTeal" "wdColorDarkYellow"
[431] "wdColorGold" "wdColorGray05"
[433] "wdColorGray10" "wdColorGray125"
[435] "wdColorGray15" "wdColorGray20"
[437] "wdColorGray25" "wdColorGray30"
[439] "wdColorGray35" "wdColorGray375"
[441] "wdColorGray40" "wdColorGray45"
[443] "wdColorGray50" "wdColorGray55"
[445] "wdColorGray60" "wdColorGray625"
[447] "wdColorGray65" "wdColorGray70"
[449] "wdColorGray75" "wdColorGray80"
[451] "wdColorGray85" "wdColorGray875"
[453] "wdColorGray90" "wdColorGray95"
[455] "wdColorGreen" "wdColorIndigo"
[457] "wdColorLavender" "wdColorLightBlue"
Upvotes: 1