我有一个表格数据,我需要导出到csv而不使用任何外部插件或API.我使用了window.open传递mime类型的方法但面临如下问题:
如何使用jquery确定系统上是否安装了Microsoft Excel或Open Office
代码应该独立于系统上安装的内容,即openoffice或ms excel.我相信CSV是可以预期在两个编辑器中显示的格式.
码
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/JavaScript">
$(document).ready(function(){
$("#btnExport").click(function(e) {
var msg = GetMimeTypes();
//OpenOffice
window.open('data:application/vnd.oasis.opendocument.spreadsheet,' + $('#dvData').html());
//MS-Excel
window.open('data:application/vnd.ms-excel,' + $('#dvData').html());
//CSV
window.open('data:application/csv,charset=utf-8,' + $('#dvData').html());
e.preventDefault();
});
});
function GetMimeTypes () {
var message = "";
// Internet Explorer supports the mimeTypes collection, but it is always empty
if (navigator.mimeTypes && navigator.mimeTypes.length > 0) {
var mimes = navigator.mimeTypes;
for (var i=0; i < mimes.length; i++) {
message += "<b>" + …Run Code Online (Sandbox Code Playgroud) 我正在使用Angular 7。
我试图在Typescript上使用fs模块打开目录。我总是遇到以下错误:“未找到模块:错误:无法解析fs”类型@节点和文件系统已安装。
我的代码:
import {Component, OnInit} from '@angular/core';
import * as fs from 'file-system';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
title = 'my-app';
constructor() {
}
ngOnInit() {
console.log(fs);
}
}
Run Code Online (Sandbox Code Playgroud)
你能帮助我吗 ?
节点:v10.14.0 Npm:v6.4.1 Angular CLI:v7.1.1