简体   繁体   English

带标题的Spotfire Webplayer交叉表导出

[英]Spotfire Webplayer crosstable export with title

I Have requirement to export Crosstable data along with Header in Spotfire. 我需要将Crosstable数据与Headfire中的Header一起导出。

1) First i tried direct excel export with location from temp folder or direct location like C:\\Export\\Text.xls. 1)首先,我尝试从位置的临时文件夹或直接位置像C:\\ Export \\ Text.xls直接Excel导出。 these are working perfect in Spotfire client. 这些在Spotfire客户端中运行完美。 But in webplayer it is not working. 但是在网络播放器中它不起作用。 It is throwing Access issue to the folder. 它将访问问题引发到文件夹。

2) Secondly i tried, With help of other forums i developed a code to convert Crosstable to text area through Iron python script and HTML to excel through JAVA script. 2)其次,我尝试过,在其他论坛的帮助下,我开发了一个代码,通过Iron python脚本将Crosstable转换为文本区域,并通过JAVA脚本将HTML转换为excel。 This is working perfect in webplayer chrome browser. 在webplayer chrome浏览器中,这是完美的工作方式。 But the issue here is it is working perfectly for the small data. 但是这里的问题是,它对于小型数据非常适用。 but i have to export around 10 MB. 但是我必须导出大约10 MB。 so it hung in both client and webplayer. 因此它挂在客户端和网络播放器上。

Can anyone help me to fix this. 谁能帮我解决这个问题。

Script 1: Cross table to HTML and then to javascript for download. 脚本1:将表格交叉链接到HTML,然后下载到javascript。 This script hangs due to size of the data. 该脚本由于数据大小而挂起。 When i use small data it works perfect in chrome. 当我使用小数据时,它在chrome中效果很好。

from Spotfire.Dxp.Application.Visuals import TablePlot, HtmlTextArea, 
CrossTablePlot
ta = visTA.As[HtmlTextArea]()
from System.IO import Path, StreamWriter
from System.Text import StringBuilder
from System.IO import *
tempFilename = MemoryStream();
tp = visDT.As[CrossTablePlot]()
writer = StreamWriter(tempFilename)
tp.ExportText(writer)
tempFilename.Seek(0,SeekOrigin.Begin);
#Build the table
sb = StringBuilder()
#Open the temp file for reading
f = open(tempFilename)
#add some scripting magic from CDN
html = ""
#build the html table
html += " <TABLE id='myTable'>\n"
html += "<THEAD>"
html += " <TR><TH>"
html += "Performance Attribution"
html += " </TH></TR> <TR><TH>"
html += Heading2
html += " </TH></TR> <TR><TH>"
html += Heading6
html += " </TH></TR> <TR><TH>"
html += Heading3
html += " </TH></TR> <TR><TH>"
html += " </TH></TR> <TR><TH><Font Size=3><B>"
html += Heading4
html += "</TD><TD></TD><TD></TD><TD>"
html += Heading5
html += "</TD><TD></TD><TD></TD><TD>"
html += "Attribution Analysis"
html += "</TD><TD></TD></B></Font></TH></TR>"
html += " <TR><TH>"
html += " </TH><TH>".join(f.readline().split("\t")).strip()
html += " </TH></TR>"
html += "</THEAD>\n"
html += "<TBODY>\n"
for line in f:
html += "<TR><TD>"
html += "</TD><TD>".join(line.split("\t")).strip()
html += "</TD></TR>\n"
f.close()
html += "</TBODY>\n"
html += "</TABLE>\n"
ta.HtmlContent = html

Script to Export from Text Area
==============================================================
jQuery.fn.fnExcelReport = function(options)
{
 var options = jQuery.extend({
    separator: ',',
    header: [],
    headerSelector: 'th',
    columnSelector: 'td',
    delivery: 'popup', // popup, value, download
    // filename: 'powered_by_sinri.csv', // filename to download
    transform_gt_lt: true // make &gt; and &lt; to > and <
 },
options);

var tab_text="<table border='2px'><tr bgcolor='#87AFC6'>";
var textRange; var j=0;
//tab = $(this); // id of table
tab = document.getElementById('myTable');
for(j = 0 ; j < tab.rows.length ; j++) 
{     
    tab_text=tab_text+tab.rows[j].innerHTML+"</tr>";
    //tab_text=tab_text+"</tr>";
}

tab_text=tab_text+"</table>";

var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE "); 

 sa = window.open('data:application/vnd.ms-excel,' + 
 encodeURIComponent(tab_text));  
return (sa);
}

$(document).ready(function () {
$('table').each(function () {
var $table = $(this);

var $button = $("<button type='button'>");
$button.text("Download");
$button.insertBefore($table);

$button.click(function () {
var csv = $table.fnExcelReport({
delivery: 'value'
  });
  });
 });
})



#Script 2: This script is working in client and not in web browsers.

from System.IO import *
from System import Environment, Threading 
username = Threading.Thread.CurrentPrincipal.Identity.Name
import clr
clr.AddReference("System.Windows.Forms")
from Spotfire.Dxp.Data.Export import DataWriterTypeIdentifiers 
from System.Windows.Forms import SaveFileDialog
from System.Diagnostics import Process, ProcessStartInfo
from Spotfire.Dxp.Application.Visuals import VisualContent
vc=Visuals.As[VisualContent]()  #Visuals = Script parameter for Table/Cross 
Table visualization
memStream = MemoryStream();
writer = 
Document.Data.CreateDataWriter(DataWriterTypeIdentifiers.ExcelXlsDataWriter);
sWriter = StreamWriter(memStream);
#Exporting the data to Memory Stream
vc.ExportText(sWriter);  #exports data in tab separated text
sReader = StreamReader(memStream);
memStream.Seek(0, SeekOrigin.Begin);
tempFolder = Path.GetTempPath()
Filenm = "Fixed_Income_Performce_Attribution.csv";
str1='\\'
print str1
newtemp = tempFolder
print newtemp
filename=newtemp+Filenm
print filename
f=open(filename,"w+")
counter=0
j=0
str1=''
f.write("Percent of Total Holdings"+'\n')
f.write(Heading2+'\n')
f.write(Heading3+'\n')
f.write(Heading6+'\n')
f.write('\n'+'\n')
while (sReader.Peek()>=0):
line=[]
counter=counter+1 #counts the number of rows in dataset
a=sReader.ReadLine()
lines=a.split("\t")
for elem in lines:
    j=j+1 # counts the number of columns in dataset
    #print elem
    if str(elem).find(",")<>-1:
        elem='"'+elem+'"'  # escaping comma already present in string
    line.append(elem)
 str1 = ','.join(str(e) for e in line)
f.write(str1+'\n')
f.close();
MemoryStream.Dispose(memStream);
sReader.Close()
Process.Start(filename)

Thanks Venkatesh 谢谢Venkatesh

For your first query (downloading to C:\\Export\\Text.xls); 对于您的第一个查询(下载到C:\\ Export \\ Text.xls); when this script runs on the web player, the files will be generated on the node manager machine (since this is where the IP script is executed). 当此脚本在Web播放器上运行时,文件将在节点管理器机器上生成(因为这是IP脚本的执行位置)。

You could output the files to a network/ shared drive, perhaps? 您可以将文件输出到网络/共享驱动器吗? You would need to add the network drive path to the allowed path section of Spotfire.Dxp.Worker.Host.exe.config and ensure it can be accessed by the node manager. 您需要将网络驱动器路径添加到Spotfire.Dxp.Worker.Host.exe.config的允许路径部分,并确保节点管理器可以访问它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM