org.ttzero.excel.entity.e3.RichStringParser Maven / Gradle / Ivy
/*
* Copyright (c) 2019-2020, [email protected] All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.ttzero.excel.entity.e3;
import org.ttzero.excel.reader.AllInOneCell;
/**
* 5.89 RSTRING
*
* This record stores a formatted text cell (Rich-Text).
* In BIFF8 it is usually replaced by the LABELSST
* record (➜5.100).
* Excel still uses this record, if it copies formatted
* text cells to the clipboard.
*
* @author guanquan.wang on 2019-02-05
*/
public class RichStringParser {
public static RichString get(Block block) {
// Size of next data
short size = block.nextShort();
RichString rs = new RichString();
// Index to row
rs.row = block.nextUnsignedShort();
// Index to column
rs.column = block.nextShort();
// Index to XF record (➜5.115)
rs.xf = block.nextShort();
// Unformatted Unicode string, 16-bit string length (➜2.5.3)
rs.value = StringParser.get16Bit(block);
// Number of Rich-Text formatting runs (rt)
short rt = block.nextShort();
FormatRun[] runs = new FormatRun[rt];
for (short i = 0; i < rt; i++) {
FormatRun r = new FormatRun();
r.firstCharacter = block.nextChar();
r.indexToFont = block.nextShort();
runs[i] = r;
}
rs.runs = runs;
return rs;
}
public static void get(Block block, AllInOneCell cell) {
// Size of next data
block.skip(2);
// Index to row
cell.row = block.nextUnsignedShort();
// Index to column
cell.column = block.nextShort();
// Index to XF record (➜5.115)
cell.xf = block.nextShort();
// Unformatted Unicode string, 16-bit string length (➜2.5.3)
cell.sValue = StringParser.get16Bit(block);
// Number of Rich-Text formatting runs (rt)
short rt = block.nextShort();
block.skip(rt << 2);
}
public static short getId() {
return ParserIdentifier.RSTRING;
}
public static class RichString extends BIFF8Cell {
String value;
FormatRun[] runs;
}
}