[xlsname,filepath]=uigetfile('*.xls');
[num,txt,raw]=xlsread([filepath,xlsname]);
clear num txt
%old version with separate prefix/name
%keywords={'name','prefix','quantity','lvlmin','lvlmax','sellvalue','faction','zone','place','map'};
%isnumber=[0,0,1,1,1,1,0,0,0,0];
%skiplist=[];
%new version, only name is relevant
keywords={'','name','qty','lvl','','','faction','zone','place',''};
isnumber=[0,0,1,1,1,1,0,0,0,0];
skiplist=[1,5,6,10];
expandedarray(1:size(raw,1),2:(size(raw,2)+1))=raw;
numlines=size(raw,1);
%separate names in prefix and name (old version only)
% for i=1:numlines
% string=raw{i,1};
% found=find(isspace(string),1,'last');
% if isempty(found)
% string1='';
% string2=string;
% else
% string1=string(1:(found-1));
% string2=string((found+1):end);
% end
% expandedarray(i,1)={string2}; %prefix
% expandedarray(i,2)={string1}; %name
% end
%remove header
expandedarray(1,:)=[];
filename=[xlsname(1:(end-4)),'_exported.lua'];
fid=fopen([filepath,filename],'w','n','UTF-8');
fprintf(fid,'BusyBeeTasks = {\n');
for i=1:(numlines-1)
fprintf(fid,' ');
%fprintf(fid,'[%i] = {id = %i,',i,i);
fprintf(fid,'{id = %i,',i);
for k=1:10
if ~isempty(find(skiplist==k,1))
continue
end
if isnumber(k)
fprintf(fid,[' ',keywords{k},' = ',num2str(expandedarray{i,k}),',']);
else
fprintf(fid,[' ',keywords{k},' = "',expandedarray{i,k},'",']);
end
end
fprintf(fid,' },\n');
end
fprintf(fid,'};\n');
fclose(fid);