createFormat method
Method that creates format object based on the format string and registers it in the workbook.
Implementation
int createFormat(String? formatString) {
if (formatString == null) {
throw Exception('formatString');
}
if (formatString.isEmpty) {
throw Exception('formatString - string cannot be empty');
}
if (formatString.contains(_default_exponential.toLowerCase())) {
formatString = formatString.replaceAll(
_default_exponential.toLowerCase(), _default_exponential);
}
// formatString = GetCustomizedString(formatString);
if (_hashFormatStrings.containsKey(formatString)) {
final Format format = _hashFormatStrings[formatString]!;
return format.index;
}
if (_parent.cultureInfo.culture == 'en-US') {
final String localStr = formatString.replaceAll(r"'$'", r'\$');
/// To know if the format string to be created is a pre-defined one.
for (final String formatStr in _hashFormatStrings.keys) {
if (formatStr.replaceAll(r'\\', '').replaceAll(r"'$'", r'\$') ==
localStr) {
final Format format = _hashFormatStrings[formatStr]!;
return format.index;
}
}
}
final int iCount = _rawFormats.length;
int index = _rawFormats.keys.toList()[iCount - 1];
/// NOTE: By Microsoft, indexes less than 163 are reserved for build-in formats.
if (index < _default_first_custom_index) {
index = _default_first_custom_index;
}
index++;
if (iCount < _max_formats_count) {
final Format format = Format(this);
format.formatString = formatString;
format.index = index;
_register(format);
} else {
return 0;
}
return index;
}