[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
ただいまコメントを受けつけておりません。
GAS で書いた。
function myFunction() {
const styles = [
{
name: 'getFontSize',
func: (val)=>{if(val) {return `font-size:${val}px;`}}
}, {
name: 'getForegroundColor',
func: (val)=>{if(val) {return `color:${val};`}}
}, {
name: 'isBold',
func: (val)=>{if(val) {return `font-weight:bold;`}}
}, {
name: 'isItalic',
func: (val)=>{if(val) {return 'font-style: italic;';}}
}, {
name: 'isStrikethrough',
func: (val)=>{if(val) {return 'text-decoration: line-through ';} else {return 'text-decoration: ';}}
}, {
name: 'isUnderline',
func: (val)=>{if(val) {return 'underline;';} else {return ';';}}
}
];
const sheet = SpreadsheetApp.getActiveSheet();
const cell = sheet.getRange(1, 1);
const elements = cell.getRichTextValue().getRuns();
const html = elements.map((element)=>{
const style = styles.map((style)=>{
return style.func(element.getTextStyle()[style.name]()) || '';
}).join('');
return `<span style="${style}">${element.getText().replaceAll('\n', '<br/>')}</span>`;
}).join('');
console.log(html);
}
ただいまコメントを受けつけておりません。