% save dataset to excel using java writer
% save_dataset_to_excel(filename,sheet,data,header,datetag);
% INPUTS:
% % - filename
%  - sheet name
%  - data
%  - header (row cell)
%  - dates strings (col cell)
function save_dataset_to_excel(filename,sheet,data,header,datetag);
[x,homeS]=system('echo $HOME');
homeS=sprintf('%s\b',homeS);
javaaddpath(['/home/gianni/Dropbox/javaxlswrite/20130227_xlwrite/20130227_xlwrite/poi_library/'])
addpath(['/home/gianni/Dropbox/javaxlswrite/20130227_xlwrite/20130227_xlwrite'])

javaaddpath(['/home/gianni/Dropbox/javaxlswrite/20130227_xlwrite/20130227_xlwrite/poi_library/dom4j-1.6.1.jar'])
javaaddpath(['/home/gianni/Dropbox/javaxlswrite/20130227_xlwrite/20130227_xlwrite/poi_library/poi-3.8-20120326.jar'])
javaaddpath(['/home/gianni/Dropbox/javaxlswrite/20130227_xlwrite/20130227_xlwrite/poi_library/poi-ooxml-3.8-20120326.jar'])
javaaddpath(['/home/gianni/Dropbox/javaxlswrite/20130227_xlwrite/20130227_xlwrite/poi_library/poi-ooxml-schemas-3.8-20120326.jar'])
javaaddpath(['/home/gianni/Dropbox/javaxlswrite/20130227_xlwrite/20130227_xlwrite/poi_library/stax-api-1.0.1.jar'])
javaaddpath(['/home/gianni/Dropbox/javaxlswrite/20130227_xlwrite/20130227_xlwrite/poi_library/xmlbeans-2.3.0.jar'])
% filename = 'capital_flows_EME.xlsx';
% numeric data matrix
% keyboard
delete([filename]);
B=data;
% dates
C=datetag;%str2cell(datetag_BOP(date1995:mtche1,:));
% headers
A = header;

% sheet = 'Quarterly';
% delete(filename);
% data={'observations',A;[char(C),num2str(B)],''};
% xlRange='A1';
% xlwrite(filename,data,sheet,xlRange)
xlRange = ['B1:',nn2an(1,length(header)+1)];
xlwrite(filename,A,sheet,xlRange)
xlRange = ['A2:A',num2str(length(datetag)+1)];
xlwrite(filename,C,sheet,xlRange)
xlRange = ['B2:',nn2an(size(B,1)+1,size(B,2)+1)];
xlwrite(filename,B,sheet,xlRange)
xlwrite(filename,{'dates'},sheet,'A1:A1')
return