название файла R!A1

This commit is contained in:
2025-07-24 05:01:44 +03:00
parent 9d07b3bab7
commit ab96a271f0
2 changed files with 26 additions and 9 deletions

View File

@@ -212,16 +212,33 @@ const ProtocolForm: FC<ProtocolFormProps> = ({ template, onSave, onBack }) => {
const a = document.createElement('a')
a.href = url
// Получаем имя файла из заголовка Content-Disposition или создаем по умолчанию
const contentDisposition = resp.headers.get('content-disposition')
let filename = `protocol_${template.name}_${new Date().toISOString().split('T')[0]}.xlsx`
// Получаем значение из ячейки R!A1 для имени файла
const filenameFromCell = engineRef.current.getCellValue('R', 0, 0) // R!A1
console.log(filenameFromCell)
let filename = 'Измените R!A1.xlsx'
if (
filenameFromCell &&
typeof filenameFromCell === 'string' &&
filenameFromCell.trim()
) {
// Очищаем имя файла от недопустимых символов
const cleanName = filenameFromCell.trim().replace(/[<>:"/\\|?*]/g, '_')
filename = `${cleanName}.xlsx`
}
// Если сервер передал имя файла в заголовке Content-Disposition, игнорируем его
// и используем строго значение из R!A1
const contentDisposition = resp.headers.get('content-disposition')
if (contentDisposition) {
const matches = contentDisposition.match(
/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/
)
if (matches && matches[1]) {
filename = matches[1].replace(/['"]/g, '')
// Оставляем возможность переопределения только если R!A1 пуста
if (!filenameFromCell || !filenameFromCell.toString().trim()) {
const matches = contentDisposition.match(
/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/
)
if (matches && matches[1]) {
filename = matches[1].replace(/['"]/g, '')
}
}
}