2010年4月5日月曜日

ScriptomとPower Pointでスライドの背景に線形グラデーションを設定する

ScriptomとPower Pointでスライドの背景に線形グラデーションを設定するには、以下のコードを実行します。

import org.codehaus.groovy.scriptom.*;
import org.codehaus.groovy.scriptom.tlb.office.*;
import org.codehaus.groovy.scriptom.tlb.office.powerpoint.*;

Scriptom.inApartment
{
ppa = new ActiveXObject("PowerPoint.Application")
ppa.Presentations.Open(new File("test1.pptx").canonicalPath,
Scriptom.MISSING, Scriptom.MISSING, MsoTriState.msoFalse)
// スライド1枚目の背景を白色と水色の線形グラデーションに設定する
slide = ppa.Presentations(1).slides(1)
slide.Background.Fill.TwoColorGradient(
MsoGradientStyle.msoGradientHorizontal,1)
slide.Background.Fill.ForeColor.RGB = 0xffddbb /* BGR*/
slide.Background.Fill.BackColor.RGB = 0xffffff /* BGR*/

ppa.Presentations(1).saveAs(new File("test3.pptx").canonicalPath)
ppa.Presentations(1).close()
ppa.quit()
}


元プレゼンテーション(test1.pptx)


出力プレゼンテーション(test3.pptx)
ScriptomとPower Pointで背景に線形グラデーションを設定したスライド

動作環境
groovy1.7.0, JDK6 Update18, PowerPoint 2007

2010年4月4日日曜日

groovyとJExcelAPIを使用してシートに画像を貼り付ける

groovyとJExcelAPIを使用してシートに画像を貼り付けるには、以下のコードを実行します。

import jxl.*;
import jxl.write.*;
import jxl.format.*;

workbook = Workbook.createWorkbook(
new File("test33.xls"),
Workbook.getWorkbook(new File("test1.xls"))
)
sheet = workbook.getSheet(0)
// A4セルにPNG形式の画像を貼り付け
width = 200/72
height = 200/18
wi = new WritableImage(0, 3, width, height, new File("sf.png"))
sheet.addImage(wi)
workbook.write()
workbook.close()


サンプルExcelブック(test1.xls)


出力Excel(test33.xls)


動作環境
groovy 1.7.0, JDK6 Upadate18, JExcelAPI 2.6.12

ScriptomとPower Pointでスライドの背景色を設定する

ScriptomとPower Pointでスライドの背景色を設定するには、以下のコードを実行します。

import org.codehaus.groovy.scriptom.*;
import org.codehaus.groovy.scriptom.tlb.office.*;
import org.codehaus.groovy.scriptom.tlb.office.powerpoint.*;

Scriptom.inApartment
{
ppa = new ActiveXObject("PowerPoint.Application")
ppa.Presentations.Open(new File("test1.pptx").canonicalPath,
Scriptom.MISSING, Scriptom.MISSING, MsoTriState.msoFalse)
// スライド1枚目を水色の背景に
slide = ppa.Presentations(1).slides(1)
slide.Background.Fill.Solid()
slide.Background.Fill.ForeColor.RGB = 0xffddbb /* BGR*/

ppa.Presentations(1).saveAs(new File("test2.pptx").canonicalPath)
ppa.Presentations(1).close()
ppa.quit()
}


元プレゼンテーション(test1.pptx)


出力プレゼンテーション(test2.pptx)
ScriptomとPower Pointで背景色を設定したスライド

動作環境
groovy1.7.0, JDK6 Update18, PowerPoint 2007

2010年4月3日土曜日

ScriptomとPower Pointでブランクスライドを追加する

ScriptomとPower Pointでブランクスライドを追加するには、以下のコードを実行します。

import org.codehaus.groovy.scriptom.*;
import org.codehaus.groovy.scriptom.tlb.office.*;
import org.codehaus.groovy.scriptom.tlb.office.powerpoint.*;

Scriptom.inApartment
{
ppa = new ActiveXObject("PowerPoint.Application")
ppa.Presentations.Open(new File("test1.pptx").canonicalPath,
Scriptom.MISSING, Scriptom.MISSING, MsoTriState.msoFalse)
ppa.Presentations(1).slides.add 1,PpSlideLayout.ppLayoutBlank
ppa.Presentations(1).saveAs(new File("test1result.pptx").canonicalPath)
ppa.Presentations(1).close()
ppa.quit()
}

元プレゼンテーション(test1.pptx)


出力プレゼンテーション(test1result.pptx)


動作環境
groovy1.7.0, JDK6 Update18, PowerPoint 2007

groovyとJExcelAPIを使用してセルを回転させる

groovyとJExcelAPIを使用してセルを回転させるには、以下のコードを実行します。

import jxl.*;
import jxl.write.*;
import jxl.format.*;

workbook = Workbook.createWorkbook(
new File("test32.xls"),
Workbook.getWorkbook(new File("test1.xls"))
)
sheet = workbook.getSheet(0)
// A1セルを-90度回転
wc = sheet.getWritableCell(0,0)
cf = new WritableCellFormat(wc.getCellFormat())
cf.setOrientation(Orientation.MINUS_90)
wc.setCellFormat(cf)
sheet.setRowView(0, 13*20*3/* 1/20 of a point */)

workbook.write()
workbook.close()


サンプルExcelブック(test1.xls)


出力Excel(test32.xls)


動作環境
groovy 1.7.0, JDK6 Upadate18, JExcelAPI 2.6.12

2010年4月2日金曜日

groovyとJExcelAPIを使用してセルで「縮小して全体を表示する」を設定する

groovyとJExcelAPIを使用してセルで「縮小して全体を表示する」を設定するには、以下のコードを実行します。

import jxl.*;
import jxl.write.*;

workbook = Workbook.createWorkbook(
new File("test31.xls"),
Workbook.getWorkbook(new File("test1.xls"))
)
sheet = workbook.getSheet(0)
// D1セルに縮小して全体を表示するを設定する
lbl = new Label(3, 0, "縮小表示テスト")
wc = sheet.getWritableCell(0,0)
cf = new WritableCellFormat(wc.getCellFormat())
cf.setShrinkToFit(true)
lbl.setCellFormat(cf)
sheet.addCell(lbl)

workbook.write()
workbook.close()


サンプルExcelブック(test1.xls)


出力Excel(test31.xls)


動作環境
groovy 1.7.0, JDK6 Upadate18, JExcelAPI 2.6.12

2010年4月1日木曜日

groovyとJExcelAPIを使用してセルを上寄せに設定する

groovyとJExcelAPIを使用してセルを上寄せに設定するには、以下のコードを実行します。

import jxl.*;
import jxl.write.*;

workbook = Workbook.createWorkbook(
new File("test30.xls"),
Workbook.getWorkbook(new File("test1.xls"))
)
sheet = workbook.getSheet(0)
// A1セルに上寄せを設定する
wc = sheet.getWritableCell(0,0)
cf = new WritableCellFormat(wc.getCellFormat())
cf.setVerticalAlignment(VerticalAlignment.TOP)
wc.setCellFormat(cf)
sheet.setRowView(0, 13*20*3/* 1/20 of a point */)

workbook.write()
workbook.close()


サンプルExcelブック(test1.xls)


出力Excel(test30.xls)


動作環境
groovy 1.7.0, JDK6 Upadate18, JExcelAPI 2.6.12

関連項目
groovy とJExcelAPIを使用してセルを右寄せに設定する