The character 0x0F
or 
, you are mentioned, is not able to store directly in XML
since it is a control character. So since *.xlsx
files stores content using XML
, that character cannot be stored directly.
Nevertheless does Microsoft defining:
ECMA-376 Part 1 22.4 Variant Types 22.4.2.4 bstr (Basic String):
22.4.2.4 bstr (Basic String)
This element defines a binary basic string variant type, which can store any valid Unicode character. Unicode characters that cannot be directly represented in XML as
defined by the XML 1.0 specification, shall be escaped using the
Unicode numerical character representation escape character format
_xHHHH_
, where H represents a hexadecimal character in the character's value. [Example: The Unicode character 8 is not permitted in an XML
1.0 document, so it shall be escaped as _x0008_
. end example] To store the literal form of an escape sequence, the initial underscore shall
itself be escaped (i.e. stored as _x005F_
). [Example: The string
literal _x0008_
would be stored as _x005F_x0008_
. end example]
The
possible values for this element are defined by the W3C XML Schema
string datatype.
This extends the W3C XML Schema string datatype. So that the character sequence _xHHHH_
does have a special meaning as a kind of entity like &#xHHHH;
.
So the following will work and Excel
will have the character 0x0F
as cell content.
import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class CreateExcelControlCharacter {
public static void main(String[] args) throws Exception {
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
String value = "PrincipalOffice\u000FDIRECTION";
value = value.replace("\u000F", "_x000F_");
cell.setCellValue(value);
wb.write(new FileOutputStream("CreateExcelControlCharacter.xlsx"));
wb.close();
}
}
But may I ask why you are needing this control character to be a Excel
cell content? That could be the answer to my question Useful use cases for escape character format _xHHHH_ in Office Open XML?.