NetSuite SuiteScript 2.0 export data to Excel file(xls)
In NetSuite SuiteScript, We usually do/implement export data to CSV, that's straight forward:
- Collect 'encoded' string to Array for column, join them with comma ',' to be a string.
- Collect each line's data same as column to push to the Array.
- Join all the Array data(include column row and all data rows) with '\n\t' to a big CSV string.
- Save the CSV string as file content then store it to file-cabinet, or write them directly in SuiteLet as a output.
Today I am going to talk about export custom NetSuite data to EXCEL file(file suffix is .xls)
Share ScreenShoot:
High level view:
- Prepared XML header string. Put in styles as desire, and workbook -> worksheet -> table
- Concat to put in dynamic cell data. So we got whole well formed xml string.
- nlapiCreateFile(SuiteScript 1.0) or file.create(SuiteScript 2.0) put in encoded xml string to create a Excel file.
- Store the file to filecabinet or set it as output of a SuiteLet(so directly download it)
Sample in SuiteScript 2.0:
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
* @author Carl, Zeng
* @description This's a sample SuiteLet script(SuiteScript 2.0) to export data
* to Excel file and directly download it in browser
*/
define(
[ 'N/file', 'N/encode' ],
/**
* @param {file}
* file
* @param {format}
* format
* @param {record}
* record
* @param {redirect}
* redirect
* @param {runtime}
* runtime
* @param {search}
* search
* @param {serverWidget}
* serverWidget
*/
function(file, encode) { /**
* Definition of the Suitelet script trigger point.
*
* @param {Object}
* context
* @param {ServerRequest}
* context.request - Encapsulation of the incoming
* request
* @param {ServerResponse}
* context.response - Encapsulation of the Suitelet
* response
* @Since 2015.2
*/
function onRequest(context) { if (context.request.method == 'GET') { var xmlStr = '<?xml version="1.0"?><?mso-application progid="Excel.Sheet"?>';
xmlStr += '<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" ';
xmlStr += 'xmlns:o="urn:schemas-microsoft-com:office:office" ';
xmlStr += 'xmlns:x="urn:schemas-microsoft-com:office:excel" ';
xmlStr += 'xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" ';
xmlStr += 'xmlns:html="http://www.w3.org/TR/REC-html40">'; xmlStr += '<Styles>'
+ '<Style ss:ID="s63">'
+ '<Font x:CharSet="204" ss:Size="12" ss:Color="#000000" ss:Bold="1" ss:Underline="Single"/>'
+ '</Style>' + '</Styles>'; xmlStr += '<Worksheet ss:Name="Sheet1">';
xmlStr += '<Table>'
+ '<Row>'
+ '<Cell ss:StyleID="s63"><Data ss:Type="String"> ID </Data></Cell>'
+ '<Cell><Data ss:Type="String"> Products Feature </Data></Cell>'
+ '</Row>'; xmlStr += '<Row>'
+ '<Cell><Data ss:Type="String">1</Data></Cell>'
+ '<Cell><Data ss:Type="String">NetSuite Export CSV</Data></Cell>'
+ '</Row>'; xmlStr += '<Row>'
+ '<Cell><Data ss:Type="String">2</Data></Cell>'
+ '<Cell><Data ss:Type="String">NetSuite Export Excel</Data></Cell>'
+ '</Row>'; xmlStr += '</Table></Worksheet></Workbook>'; var strXmlEncoded = encode.convert({
string : xmlStr,
inputEncoding : encode.Encoding.UTF_8,
outputEncoding : encode.Encoding.BASE_64
}); var objXlsFile = file.create({
name : 'sampleExport.xls',
fileType : file.Type.EXCEL,
contents : strXmlEncoded
});
// Optional: you can choose to save it to file cabinet
// objXlsFile.folder = -14;
// var intFileId = objXlsFile.save(); context.response.writeFile({
file : objXlsFile
});
} } return {
onRequest : onRequest
}; });
NetSuite SuiteScript 2.0 export data to Excel file(xls)的更多相关文章
- C# Note38: Export data into Excel
Microsoft.Office.Interop.Excel You have to have Excel installed. Add a reference to your project to ...
- csharp:using OpenXml SDK 2.0 and ClosedXML read excel file
https://openxmlexporttoexcel.codeplex.com/ http://referencesource.microsoft.com/ 引用: using System; u ...
- How to create a zip file in NetSuite SuiteScript 2.0 如何在现有SuiteScript中创建和下载ZIP压缩文档
Background We all knows that: NetSuite filecabinet provided a feature to download a folder to a zip ...
- Export SQLite data to Excel in iOS programmatically(OC)
//For the app I have that did this, the SQLite data was fairly large. Therefore, I used a background ...
- Export Data from mysql Workbench 6.0
原文地址:export-data-from-mysql-workbench-6-0 问题描述 I'm trying to export my database, using MySQL Workben ...
- csharp: Export DataSet into Excel and import all the Excel sheets to DataSet
/// <summary> /// Export DataSet into Excel /// </summary> /// <param name="send ...
- Insert data from excel to database
USE ESPA Truncate table dbo.Interface_Customer --Delete the table data but retain the structure exec ...
- csharp: Export DataTable to Excel using OpenXml 2.5 in asp.net
//https://www.microsoft.com/en-us/download/details.aspx?id=5124 Open XML SDK 2.0 for Microsoft Offic ...
- csharp: Export or Import excel using MyXls,Spire.Xls
excel 2003 (效果不太理想) using System; using System.Collections.Generic; using System.ComponentModel; usi ...
随机推荐
- MXNET安装过程中遇到libinfo导入不了的问题解决
今天尝试安装windows版本的MXNET,在按照官网的运行了python的setup之后,import mxnet时出现如下错误:cannot import name libinfo,在网上查找发现 ...
- 手势响应 ,避免点击多个cell同时响应同一手势多次,只响应第一个cell
http://www.cnblogs.com/wfwenchao/articles/3700205.html UIView除了负责展示内容给用户外还负责响应用户事件.本章主要介绍UIView用户交互相 ...
- ACM集训的第。。。诶~不知道第几题=.=
题目: 郭铮鹏认为排序是一种很频繁的计算任务,所以他考虑了一个简单的问题:现在最多只有三值的排序问题.一个实际的例子是,当我们给某项竞赛的优胜者按金银铜牌排序的时候.在这个任务中可能的值只有三种1,2 ...
- [转]AS3 int uint Number
转自:http://luhantu.iteye.com/blog/1910301 AS3 int uint Number 博客分类: AS3 flex number 类型 1) int 类可使用表示 ...
- VS2012完全卸载与VS2013安装
项目本来使用的是vs2012 Ultimate,也一直跟随ms的节奏安装了从1到4的update,但一些无法忍受的问题却一直没有解决: 1.偶尔出现要等待编辑器响应的情况: 2.偶尔输入了冒号也不会出 ...
- Android 基于Android的手机邮件收发(JavaMail)之四(邮件的发送)
上一个邮件的接受,因为不当操作,保存未完成,一切东西都得从头开始那就先从邮件发送来吧. 先下我们做一个较为简单的邮件发送 以下是源代码:相信看过上篇文章所给连接的人,对于javamail应该都有了一定 ...
- MWeb 2.0 测试版可以下载啦,这次是公开测试,感兴趣的朋友可以试试
2.0 版是 MWeb 发布以来,最重要的一个版本.MWeb 自去年一月份发布以来,获得了很多朋友的建议,在此非常感谢!没有你们,2.0 版可能就不能出来!然后再次感谢 Producter: http ...
- github Android-Universal-Image-Loader
目存在于Github上面https://github.com/nostra13/Android-Universal-Image-Loader,我们可以先看看这个开源库存在哪些特征 多线程下载图片,图片 ...
- XEN的启动信息输出到“Platform timer is 14.318MHz HPET”就暂停接收的解决办法
使用Serial Over Lan(SOL)来双机调试 XEN,在 XEN 启动时,引导信息输出到以下这一句时,就不再发送调试信息了: ...(XEN) Intel machine check rep ...
- 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数016,xld,xld轮廓
<zw版·Halcon-delphi系列原创教程> Halcon分类函数016,xld,xld轮廓 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换:“ ...