セルから HTML5 文字列を取得
Contents
[
Hide
]
可能な使用シナリオ
Aspose.Cellsは、ブールパラメータを受け取るCell.getHtmlString(boolean)メソッドを使用してセルのHTML文字列を返します。パラメータにfalseを渡すと通常のHTMLを返し、trueを渡すとHTML5文字列を返します。
セルからHTML5文字列を取得
次のサンプルコードはワークブックオブジェクトを作成し、最初のシートのセルA1にいくつかのテキストを追加します。その後、セルA1から通常のHTMLとHTML5文字列をCell.getHtmlString(boolean)メソッドを使って取得し、コンソールに出力します。
サンプルコード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const AsposeCells = require("aspose.cells.node"); | |
const path = require("path"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Create workbook. | |
const wb = new AsposeCells.Workbook(); | |
// Access first worksheet. | |
const ws = wb.getWorksheets().get(0); | |
// Access cell A1 and put some text inside it. | |
const cell = ws.getCells().get("A1"); | |
cell.putValue("This is some text."); | |
// Get the Normal and Html5 strings. | |
const strNormal = cell.getHtmlString(false); | |
const strHtml5 = cell.getHtmlString(true); | |
// Print the Normal and Html5 strings on console. | |
console.log("Normal:\r\n" + strNormal); | |
console.log(); | |
console.log("Html5:\r\n" + strHtml5); |
コンソール出力
Normal:
<Font Style="FONT-FAMILY: Arial;FONT-SIZE: 10pt;COLOR: #000000;">This is some text.</Font>
Html5:
<div Style="FONT-FAMILY: Arial;FONT-SIZE: 10pt;COLOR: #000000;">This is some text.</div>