название файла R!A1
This commit is contained in:
@@ -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, '')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ const TemplateCard: React.FC<TemplateCardProps> = ({
|
||||
}}
|
||||
>
|
||||
<FileText className="mr-2 h-4 w-4" />
|
||||
{isConfigured ? 'Создать протокол' : 'Требует настройки'}
|
||||
{isConfigured ? 'Создать' : 'Требует настройки'}
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
|
||||
Reference in New Issue
Block a user