Preserve QExcell font sizes

This commit is contained in:
Курнат Андрей
2026-06-01 06:57:48 +03:00
parent 9f5a003bae
commit fec79a8a93
6 changed files with 59 additions and 15 deletions
+28
View File
@@ -81,6 +81,7 @@ const horizontalAlignOptions = [
{ value: "center", label: "По центру", icon: AlignCenter },
{ value: "right", label: "По правому краю", icon: AlignRight }
] as const;
const fontSizeOptions = [10, 11, 12, 14, 16, 18, 20, 24];
function normalizedLinkInput(value: string | null) {
const raw = value?.trim();
@@ -108,10 +109,12 @@ function normalizedCellFormat(format: CellFormat): CellFormat | undefined {
const fillColor = normalizedFillColor(format.fillColor);
const horizontalAlign = normalizedHorizontalAlign(format.horizontalAlign);
const numberFormat = format.numberFormat?.trim();
const fontSize = normalizedFontSize(format.fontSize);
const normalized: CellFormat = {
...(format.bold ? { bold: true } : {}),
...(format.italics ? { italics: true } : {}),
...(format.underline ? { underline: true } : {}),
...(fontSize ? { fontSize } : {}),
...(textColor ? { textColor } : {}),
...(fillColor ? { fillColor } : {}),
...(horizontalAlign ? { horizontalAlign } : {}),
@@ -126,6 +129,7 @@ function cellInputStyle(format?: CellFormat): CSSProperties {
...(format?.bold ? { fontWeight: 700 } : {}),
...(format?.italics ? { fontStyle: "italic" } : {}),
...(format?.underline ? { textDecoration: "underline" } : {}),
...(format?.fontSize ? { fontSize: `${format.fontSize}pt` } : {}),
...(format?.textColor ? { color: `#${format.textColor}` } : {}),
...(format?.fillColor ? { backgroundColor: `#${format.fillColor}` } : {}),
...(format?.horizontalAlign ? { textAlign: format.horizontalAlign } : {})
@@ -136,6 +140,15 @@ function normalizedHorizontalAlign(value?: string) {
return value === "left" || value === "center" || value === "right" ? value : "";
}
function normalizedFontSize(value?: number) {
if (!Number.isFinite(value) || !value || value <= 0) {
return undefined;
}
const normalized = Math.round(value * 2) / 2;
return normalized === 11 ? undefined : normalized;
}
function normalizedChartRange(value: string) {
const raw = value.trim().replace(/\$/g, "").toUpperCase();
const [start, end = start] = raw.split(":");
@@ -493,6 +506,21 @@ export function QExcell({ workbook, onChange }: QExcellProps) {
</button>
);
})}
<select
value={selectedCellFormat.fontSize ?? ""}
onChange={(event) =>
updateCellFormat(selectedCell, { fontSize: event.target.value ? Number(event.target.value) : undefined })
}
aria-label="Размер шрифта"
title="Размер шрифта"
>
<option value="">Размер</option>
{fontSizeOptions.map((fontSize) => (
<option key={fontSize} value={fontSize}>
{fontSize}
</option>
))}
</select>
<div className="fill-swatches" aria-label="Заливка">
<PaintBucket size={16} aria-hidden="true" />
{fillSwatches.map((swatch) => (