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. yii2.0场景的使用

  2. Object C中Block用法

    先了解定义C语言的函数指针! int sum (int x, int y) { return x+ y; } // 定义函数 int (*p)(int, int) = sum; NSLog(, )); ...

  3. java替换包含html标签

    说明一下,该文档内容抄自开源中国里的谋篇文章,由于抄袭时间过于久远,已经找不到博主了!暂不能说明出处,源码博主看见勿气,皆可联系本人! 我的博客,文章属于个人收藏,以解日后需要之急! package ...

  4. Ubuntu 14.04 编译安装 husky

    简介 Husky是一个大数据分布式开发框架,用C++开发,因为粗粒度(coarse-grained)平台(如Spark,Hadoop,Flink)MR耗时太大,然后细粒度(fine-grained)平 ...

  5. MVC 上传 下载

    [上传]带进度条 view  注:添加easyui的js文件 <script type="text/javascript"> function fileSelected ...

  6. Python学习【第五篇】循环语句

    Python循环语句 接下来将介绍Python的循环语句,程序在一般情况下是按顺序执行的. 编程语言提供了各种控制结构,允许更复杂的执行路径. 循环语句允许我们执行一个语句或语句组多次. Python ...

  7. Testlink与Redmine关联

    TestLink是一个开源的测试管理工具,它可以有效地管理整个测试流程(测试需求, 测试计划, 测试用例, 测试执行, 测试结果分析),但不能和开发流程统一起来,从而不能及时参与到开发中去,不能使项目 ...

  8. [SharePoint 2010] 自定义字段类型开发(二)

    在SharePoint 2010中实现View Action Button效果. http://www.sharepointblogs.be/blogs/vandest/archive/2008/06 ...

  9. 区间重叠计算及IntervalTree初识

    最近被人问到这样一个问题的解决方案:在一个餐馆的预定系统中,接受用户在未来任意一段时间内的预订用餐,用户在预订的时候需要提供用餐的开始时间和结束,餐馆的餐桌是用限的,问题是,系统要在最快的时间段计算出 ...

  10. IOS 调用系统照相机和相册

    /** *  调用照相机 */ - (void)openCamera { UIImagePickerController *picker = [[UIImagePickerController all ...