In NetSuite SuiteScript, We usually do/implement export data to CSV, that's straight forward:

  1. Collect 'encoded' string to Array for column, join them with comma ',' to be a string.
  2. Collect each line's data same as column to push to the Array.
  3. Join all the Array data(include column row and all data rows) with '\n\t' to a big CSV string.
  4. 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:


  1. Prepared XML header string.  Put in styles as desire, and workbook -> worksheet -> table
  2. Concat to put in dynamic cell data.  So we got whole well formed xml string.
  3. nlapiCreateFile(SuiteScript 1.0) or file.create(SuiteScript 2.0) put in encoded xml string to create a Excel file.
  4. 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)的更多相关文章

  1. C# Note38: Export data into Excel

    Microsoft.Office.Interop.Excel You have to have Excel installed. Add a reference to your project to ...

  2. csharp:using OpenXml SDK 2.0 and ClosedXML read excel file

    https://openxmlexporttoexcel.codeplex.com/ http://referencesource.microsoft.com/ 引用: using System; u ...

  3. 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 ...

  4. 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 ...

  5. Export Data from mysql Workbench 6.0

    原文地址:export-data-from-mysql-workbench-6-0 问题描述 I'm trying to export my database, using MySQL Workben ...

  6. csharp: Export DataSet into Excel and import all the Excel sheets to DataSet

    /// <summary> /// Export DataSet into Excel /// </summary> /// <param name="send ...

  7. Insert data from excel to database

    USE ESPA Truncate table dbo.Interface_Customer --Delete the table data but retain the structure exec ...

  8. 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 ...

  9. csharp: Export or Import excel using MyXls,Spire.Xls

    excel 2003 (效果不太理想) using System; using System.Collections.Generic; using System.ComponentModel; usi ...

随机推荐

  1. mysql临时禁用触发器

    mysql支持设定session变量,并且有带入到触发器中使用的能力,故可以间接的设置触发器失效 思路是: 在执行前设定一个session变量,执行过程中判断该变量的值(没有设定该变量的值时该变量默认 ...

  2. iOS上线...踩坑

    总结一下上线过程中出现的问题: 1.AppStore不允许app中出现下载别的app的提示 (例如:三方登录的时候,检测到手机未安装QQ,微信,微博,提示你的设备未安装!❌❌❌ 正确的做法:未安装的, ...

  3. C++学习笔记 知识集锦(一)

    1.内存管理的开销 2.函数调用框架 3.类为什么要定义在头文件 4.C++的组合 5.在类的外部定义成员函数 6.bool类型为什么可以当做int类型 7.无符号保留原则 8.C++类型检查 9.何 ...

  4. 委托学习笔记后续:泛型委托及委托中所涉及到匿名方法、Lambda表达式

    引言: 最初学习c#时,感觉委托.事件这块很难,其中在学习的过程中还写了一篇学习笔记:委托.事件学习笔记.今天重新温故委托.事件,并且把最近学习到和委托相关的匿名方法.Lambda表达式及泛型委托记录 ...

  5. u-boot FIT image介绍_转自“蜗窝科技”

    转自:http://www.wowotech.net/u-boot/fit_image_overview.html 1. 前言 Linux kernel在ARM架构中引入设备树device tree( ...

  6. centos7优化内核参数详解

    cat /etc/sysctl.conf #CTCDN系统优化参数 #关闭ipv6 net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.d ...

  7. 几种获取IP 根据IP获取地址的方法 JS,第三方 新浪 网易 腾讯

    第一种是利用纯真ip数据库,这个可以在网上找到很多,缺点是更新有点慢. 第二种是利用门户网站的接口 目前已知的有腾讯.新浪.网易.搜狐和Google提供IP地址查询API,但是找得到的只有腾讯.新浪和 ...

  8. EXC_ARM_DA_ALIGN

    ios 版本上的问题  armv7  ipad2 int64 t = *(int64*)pBuff; 如果pBuff不是8字节对齐的地址就 crash 变通的方法是通过memcpy __sync_fe ...

  9. ps commad

    要对系统中进程进行监测控制,查看状态,内存,CPU的使用情况,使用命令:/bin/ps (1)         ps :是显示瞬间进程的状态,并不动态连续: (2)         top:如果想对进 ...

  10. zabbix利用自带的模板监控mysql数据库

    zabbix利用自带的模板监控mysql数据库 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 有些东西你不会的时候觉得它特别难,但是当你去做的时候就发现如此的简单~zabbix功能 ...