Не пойму как мне обработать тескт который я получил в переменную contents?
var filesExt = ['htm']; // массив расширений
var docx = document.getElementById("fileInput");
docx.addEventListener('change', function(e) {
var parts = $(this).val().split('.');
if(filesExt.join().search(parts[parts.length - 1]) != -1){
alert('Good!');
var file = docx.files[0];
var textType = /text.*/;
if (file.type.match(textType)) {
var reader = new FileReader();
reader.onload = function(e) {
var contents = event.target.result;
console.log(contents);
}
reader.readAsText(file);
} else {
alert("File not supported!");
}
} else {
alert('WTF?!');
}
});
что только я не делал, и обычными методами, и jquery, и с какими только переменными не пытался. Все время undefined,null,init,object, но текст так и не достал... contents выводится в алерт и консоль так как нужно, готовая страница, но вот как ее отредактировать?
вот что я вижу и в алерт и в консоль лог. Но больше никуда не могу вывести.
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 14">
<link id=Main-File rel=Main-File href="../Новый%20текстовый%20документ.xls">
<link rel=File-List href=filelist.xml>
<link rel=Stylesheet href=stylesheet.css>
<style>
<!--table
{mso-displayed-decimal-separator:",";
mso-displayed-thousand-separator:" ";}
@page
{margin:1.0in .75in 1.0in .75in;
mso-header-margin:.5in;
mso-footer-margin:.5in;}
-->
</style>
<![if !supportTabStrip]><script language="JavaScript">
<!--
function fnUpdateTabs()
{
if (parent.window.g_iIEVer>=4) {
if (parent.document.readyState=="complete"
&& parent.frames['frTabs'].document.readyState=="complete")
parent.fnSetActiveSheet(0);
else
window.setTimeout("fnUpdateTabs();",150);
}
}
if (window.name!="frSheet")
window.location.replace("../Новый%20текстовый%20документ.xls");
else
fnUpdateTabs();
//-->
</script>
<![endif]>
</head>
<body link=blue vlink=purple>
<table border=0 cellpadding=0 cellspacing=0 width=784 style='border-collapse:
collapse;table-layout:fixed;width:588pt'>
<col width=200 span=2 style='mso-width-source:userset;mso-width-alt:7314;
width:150pt'>
<col width=40 style='mso-width-source:userset;mso-width-alt:1462;width:30pt'>
<col width=120 style='mso-width-source:userset;mso-width-alt:4388;width:90pt'>
<col width=40 style='mso-width-source:userset;mso-width-alt:1462;width:30pt'>
<col width=120 style='mso-width-source:userset;mso-width-alt:4388;width:90pt'>
<col width=64 style='width:48pt'>
<tr height=21 style='height:15.0pt'>
<td height=20 class=xl65 width=200 style='height:15.0pt;width:150pt'></td>
<td width=200 style='width:150pt'></td>
<td width=40 style='width:30pt'></td>
<td width=120 style='width:90pt'></td>
<td width=40 style='width:30pt'></td>
<td width=120 style='width:90pt'></td>
<td width=64 style='width:48pt'></td>
</tr>
<tr height=60 style='mso-height-source:userset;height:45.0pt'>
<td colspan=6 height=60 class=xl73 width=720 style='border-right:.5pt solid black;
height:45.0pt;width:540pt'> </td>
<td class=xl65 width=64 style='width:48pt'></td>
</tr>
<tr height=21 style='height:15.75pt'>
<td height=21 class=xl65 width=200 style='height:15.75pt;width:150pt'></td>
<td class=xl65 width=200 style='width:150pt'></td>
<td colspan=5 style='mso-ignore:colspan'></td>
</tr>
<tr height=80 style='mso-height-source:userset;height:60.0pt'>
<td height=80 class=xl66 width=200 style='height:60.0pt;width:150pt'>Наименование
оборудования</td>
<td class=xl67 width=200 style='width:150pt'>Тип</td>
<td class=xl67 width=40 style='width:30pt'>Ед.
Изм.</td>
<td class=xl68>Цена</td>
<td class=xl68>К-во</td>
<td class=xl69>Сумма</td>
<td></td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl72 width=200 style='height:15.0pt;width:150pt'> </td>
<td class=xl71 width=200 style='width:150pt'> </td>
<td class=xl72 width=40 style='width:30pt'> </td>
<td class=xl72> </td>
<td class=xl72> </td>
<td class=xl72> </td>
<td></td>
</tr>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl72 width=200 style='height:15.0pt;width:150pt'> </td>
<td class=xl71 width=200 style='width:150pt'> </td>
<td class=xl72 width=40 style='width:30pt'> </td>
<td class=xl72> </td>
<td class=xl72> </td>
<td class=xl72> </td>
<td></td>
</tr>
<![if supportMisalignedColumns]>
<tr height=0 style='display:none'>
<td width=200 style='width:150pt'></td>
<td width=200 style='width:150pt'></td>
<td width=40 style='width:30pt'></td>
<td width=120 style='width:90pt'></td>
<td width=40 style='width:30pt'></td>
<td width=120 style='width:90pt'></td>
<td width=64 style='width:48pt'></td>
</tr>
<![endif]>
</table>
</body>
</html>
мне нужно вот в этой строчке после текста вставить свой текст.
<td height=20 class=xl72 width=200 style='height:15.0pt;width:150pt'>
Это будет заполненная ячейка таблицы.
ПРОДОЛЖЕНИЕ!
var contents='';
var Loaded='';
var filesExt = ['htm']; // массив расширений
var docx = document.getElementById("fileInput");
docx.addEventListener('change', function(e) {
var parts = $(this).val().split('.');
if(filesExt.join().search(parts[parts.length - 1]) != -1){
alert('Good!');
var file = docx.files[0];
var textType = /text.*/;
var loaded='';
if (file.type.match(textType)) {
var reader = new FileReader();
reader.onload = function(e) {
window.contents = event.target.result;
//if (contents!=''){loaded=1;}
console.log(window.contents);
window.Loaded=1;
console.log(window.Loaded+'_1');
}
reader.readAsText(file);
if(window.Loaded!='undefined') {console.log(window.contents);}
console.log(window.Loaded+'_2');
} else {
alert("File not supported!");
}
} else {
alert('WTF?!');
}
});
});
я работаю с контентс до того, как в него загрузятся данные и здесь Loaded тоже все равно вызывается, не смотря на то что она не определена. Либо я не могу вытащить переменную контентс из функции. Вопрос как обработать контентс после того, как в нее загрузится инфа?