我希望网站上的excel文件在点击时在Excel中打开,不会保存在桌面上,或者在浏览器中嵌入打开等等.现在显然这一切都取决于每个用户的所有配置,但最好的内容类型是什么和其他设置,以实现大部分时间?
MS Excel具有以下观察到的MIME类型:
application/vnd.ms-excel (官方)application/msexcelapplication/x-msexcelapplication/x-ms-excelapplication/x-excelapplication/x-dos_ms_excelapplication/xlsapplication/x-xlsapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet (XLSX)是否有任何一种适用于所有版本的类型?如果没有,我们是否需要response.setContentType()单独设置这些mime类型中的每一个?
此外,我们在应用程序中使用文件流来显示文档(不仅仅是excel - 任何类型的文档).这样做,如果用户选择保存文件,我们如何保留文件名 - 目前,呈现文件的servlet名称显示为默认名称.
我正在寻找一种简单的方法来获取文件扩展名不正确或没有给出的mime类型,类似于.Net中的这个问题.
我有两个申请,如下所述:
截至目前,我已video/mp4在IIS7 mime类型部分中为.mp4 添加了mime类型.
当我试图在iPad下载.mp4文件时,我看到一个带有十字箭头的深黑色屏幕.任何人都可以帮我解决这个问题.
请告诉我video/mp4.mp4 的mime类型是否正确.
我想从存储中仅选择pdf,xlsx和txt文件,但intent.setType只能执行一个文件(仅限eg.txt文件(或)pdf文件).是否可以通过编码intent.setType()来获取所有三个文件,并且有办法吗?
这是我的一些代码.
private void showFileChooser() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("application/pdf");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(
Intent.createChooser(intent, "Select txt file"),
0);
} catch (android.content.ActivityNotFoundException ex) {
// Potentially direct the user to the Market with a Dialog
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用PHPWord生成word文档.并且可以成功生成文档.但是有一个问题是我生成的word文档将保存在服务器上.我怎样才能立即下载?
样品:
$PHPWord = new PHPWord();
//Searching for values to replace
$document = $PHPWord->loadTemplate('doc/Temp1.docx');
$document->setValue('Name', $Name);
$document->setValue('No', $No);
$document->save('php://output'); //it auto save into my 'doc' directory.
Run Code Online (Sandbox Code Playgroud)
我如何链接到标题下载它如下:
header("Content-Disposition: attachment; filename='php://output'"); //not sure how to link this filename to the php://output..
Run Code Online (Sandbox Code Playgroud)
好心提醒.
我在.NETCoreApp 1.1中使用OpenXml 2.7.2生成了一个excel文件,并将其保存到项目文件夹中.然后在我的函数中,我读取字节并尝试将其作为文件返回.我没有收到错误,但在回复中我只是得到了二进制文件.所以它似乎工作,但没有下载.
这是我的代码:
[HttpGet]
[Route("export")]
public IActionResult Export()
{
return File(System.IO.File.ReadAllBytes(filePath),
contentType: "application/octet-stream",
fileDownloadName: "MySheet.xlsx");
}
Run Code Online (Sandbox Code Playgroud)
如果有人知道如何在.net核心中提供可下载的excel文件,请告诉我.任何帮助表示赞赏谢谢!
UPDATE
我不确定腐败是否与使用OpenXml生成excel文件有关,因为即使我尝试导出未使用OpenXml生成的空文件,我也会收到相同的错误消息"文件已损坏且无法打开" .它也与Excel 2016不完全相关,因为我可以打开其他excel文件.
我正面临一个问题,我用Angular 1下载了一个Excel文件,但是如果我在Angular 5中实现了相同的代码,则会显示您的文件已损坏的错误.我的回复是在ArrayBuffer中,我无法读取该文件.
以下是我的代码:
服务:
DownloadData(model:requiredParams):Observable<any>{
const headers = new Headers();
const requestOptions = new RequestOptions({ headers: headers });
requestOptions.headers.append('Content-Type', 'application/json');
const body = JSON.stringify(model);
return this.http.post(url, body, requestOptions)
.map((res:any) => res)
.catch((e: any) => Observable.throw(this.errorHandler(e)));
}
Run Code Online (Sandbox Code Playgroud)
零件:
exportToExcel() {
this.loadingOverlayFlag = true;
this.podashboardService.DownloadData(this.data).subscribe(result=>{
console.log(result);
this.downloadFile(result._body,'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'export.xlsx');
})
}
downloadFile(blob: any, type: string, filename: string) {
var binaryData = [];
binaryData.push(blob);
const url = window.URL.createObjectURL(new Blob(binaryData, {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"})); // <-- work with blob directly
// create hidden dom …Run Code Online (Sandbox Code Playgroud) 我将选定的文件上传到服务器,但我知道我想restrick用户只选择文档文件(.doc,.pdf等)和图像文件.
现在我的代码适用于所有文件,它提取uri的所有文件,所以请告诉我如何限制用户只选择特定类型的文件.
这是我选择任何文件的代码.
Intent i=new Intent();
i.setType("*/*");
i.setAction(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(Intent.createChooser(i, "abc"),requestCode);
Run Code Online (Sandbox Code Playgroud) 我正在开发一个允许教师上传文件和学生下载文件的网站。但是,有一个问题。Microsoft Word (.docx) 文件可以完美下载,但是在下载 excel (xlsx) 文件时,excel 会显示“此文件已损坏,无法打开”对话框。对此的任何帮助将不胜感激!
我的下载代码如下:
case 'xlsx':
header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Pragma: no-cache');
readfile('./uploads/resources/courses/' . $filename);
break;
Run Code Online (Sandbox Code Playgroud)