название файла R!A1
This commit is contained in:
@@ -212,11 +212,27 @@ const ProtocolForm: FC<ProtocolFormProps> = ({ template, onSave, onBack }) => {
|
|||||||
const a = document.createElement('a')
|
const a = document.createElement('a')
|
||||||
a.href = url
|
a.href = url
|
||||||
|
|
||||||
// Получаем имя файла из заголовка Content-Disposition или создаем по умолчанию
|
// Получаем значение из ячейки R!A1 для имени файла
|
||||||
const contentDisposition = resp.headers.get('content-disposition')
|
const filenameFromCell = engineRef.current.getCellValue('R', 0, 0) // R!A1
|
||||||
let filename = `protocol_${template.name}_${new Date().toISOString().split('T')[0]}.xlsx`
|
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) {
|
if (contentDisposition) {
|
||||||
|
// Оставляем возможность переопределения только если R!A1 пуста
|
||||||
|
if (!filenameFromCell || !filenameFromCell.toString().trim()) {
|
||||||
const matches = contentDisposition.match(
|
const matches = contentDisposition.match(
|
||||||
/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/
|
/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/
|
||||||
)
|
)
|
||||||
@@ -224,6 +240,7 @@ const ProtocolForm: FC<ProtocolFormProps> = ({ template, onSave, onBack }) => {
|
|||||||
filename = matches[1].replace(/['"]/g, '')
|
filename = matches[1].replace(/['"]/g, '')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
a.download = filename
|
a.download = filename
|
||||||
document.body.appendChild(a)
|
document.body.appendChild(a)
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ const TemplateCard: React.FC<TemplateCardProps> = ({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<FileText className="mr-2 h-4 w-4" />
|
<FileText className="mr-2 h-4 w-4" />
|
||||||
{isConfigured ? 'Создать протокол' : 'Требует настройки'}
|
{isConfigured ? 'Создать' : 'Требует настройки'}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
|
|||||||
Reference in New Issue
Block a user