<html>
<!-- A new version of my Word to CSV converter -->
<!-- will work only locally on Windows machine, I guess, in IE only -->
<!-- Just copy and paste all tis text to your local HTML file -->
<head>
<style type="text/css">
p {font-family: arial; font-size: 8 pt; margin-left: 5; font-weight: normal; margin-top: 1; margin-bottom: 3}
table {margin-left: 5; font-size: 8 pt}
div {margin-left: 20; border-left: 1px dotted}
.folder {background-color: yellow; font-size: 8pt}
.header {font-family: arial; font-size: 10pt; font-weight: bold}
.pane {margin-left: 0; background-color: yellow; font-size: 10 pt}
input {font-size: 8pt}
select {font-size: 8pt}
</style>
</head>
<body>
</body>
<script>
var root_arr = new Array; //stack for current parents
var header_arr = new Array; //all headings
var is_open = 0;
var do_markup = 0;
var convert_numbers = 0;
var cur_root;
var active_table = 0;
var w; // = new ActiveXObject("Word.Application");
var doc; // = w.Documents.Open("");
do_pane();
function do_pane(){
var f, s;
f = document.createElement("form");
f.className = "pane";
s = "<table cellpadding = \"0\"><tr><td>Document:</td><td><input type = \"file\" name = \"filename\" size = \"50\"/>";
s += "<input type = \"button\" value = \"Parse\" onclick = \"open_doc(filename.value)\"/>";
s += "<input type = \"checkbox\" onclick = \"with_markup()\">Insert bookmarks</input></td></tr>";
s += "<tr><td>HTTP path:</td><td><input type = \"text\" name = \"http_path\" size = \"50\" value = \"your_app_dir/your_doc_dir/your_doc.html\"/>";
s += "<input type = \"checkbox\" onclick = \"convert_nums()\">Convert numbers to text in document</input></td></tr>";
s += "<tr><td>Output file:</td><td><input type = \"file\" name = \"outfile\" size = \"50\"/>";
s += "<input type = \"button\" value = \"Preview\" onclick = \"save_csv(0)\"/>";
s += "<input type = \"button\" value = \"Output\" onclick = \"save_csv(outfile.value)\"/>";
s += "<input type = \"button\" value = \"Help\" onclick = \"help()\"/></td>";
s += "</tr></table>";
f.innerHTML = s;
document.childNodes[0].childNodes[1].appendChild(f);
}
function with_markup(){
do_markup = Math.abs(do_markup - 1);
}
function save_csv(target){
if (is_open == 0){
alert ("Parse a document before!");
return;
}
var i, j, k, s = "", s1 = "", n, d, w;
for (i in header_arr){
if (header_arr.checked == 1 & i > 0){
s1 = "";
s += (header_arr.name + ",");
j = header_arr.div.childNodes.length;
if (j > 0){
for (k = 0; k < j; k++){
n = header_arr.div.childNodes[k];
if (n.tagName == "P"){
s1 += n.outerHTML;
}
if (n.tagName == "SPAN"){
s1 += n.innerHTML;
}
}
}
s1 = s1.replace(/\n|\r/g, "");
s1 = s1.replace(/\,/g, "\&\#44;");
s += s1 + "\n";
}
}
if (target == 0){
w = window.open();
d = w.document.open("text/plain");
d.write(s);
}
else if (target != ""){
var fso, file;
fso = new ActiveXObject("Scripting.FileSystemObject");
file = fso.CreateTextFile(target);
file.Write(s);
alert("Done");
}
}
function check_header(id){
header_arr[id].checked = Math.abs(header_arr[id].checked - 1);
}
function convert_nums(){
convert_numbers = Math.abs(convert_numbers - 1);
}
function open_doc(path){
if (path == ""){
alert("Select a file");
return;
}
if (is_open == 1){
alert("Click Refresh to work with new document.");
return;
}
w = new ActiveXObject("Word.Application");
w.visible = true;
doc = w.Documents.Open(path);
if (convert_numbers != 0){
doc.ConvertNumbersToText();
alert("Autonumbers in source document have been converted to text.");
}
root_arr[0] = new Object;
root_arr[0].lvl = -1;
root_arr[0].div = document.childNodes[0].childNodes[1];
cur_root = root_arr[0].div;
is_open = 1;
write_tree();
if (do_markup == 0){
//doc.Close();
w.Quit();
}
else {
alert("Bookmarks have been written to source document.");
}
}
function add_node(parent, id, level, name){
var h;
var a, d, t, i = 0, n;
h = document.createElement("h1");
h.setAttribute("id", id);
h.className = "header";
n = name.replace(/\r|\n/, "");
n = n.replace(/\,|\t/g, " ");
s = "<a class = \"folder\" href = \"javascript:collapse_tree(" + id + ")\">|/ - /</a>";
s += "<input type = \"checkbox\" checked = \"true\" onclick = \"check_header(" + id + ")\"/>";
s += n;
h.innerHTML = s;
d = document.createElement("div")
d.setAttribute("id", "d" + id);
h.appendChild(d);
header_arr[id] = new Object;
header_arr[id].name = n;
header_arr[id].collapsed = 0;
header_arr[id].checked = 1;
header_arr[id].div = d;
if (do_markup == 1){
p = document.createElement("p");
s = "<a href = \"http://" + document.forms[0].http_path.value + "#b" + id + "\">Link to [" + n + "]</a>";
p.innerHTML = s;
d.appendChild(p);
}
parent.appendChild(h);
root_arr.length++;
i = root_arr.length - 1;
root_arr = new Object;
root_arr.lvl = level;
root_arr.div = d;
}
function write_tree(){
var i = 0, j = 0, k = 0, m = 0;
var para, cur_lev = 0;
var level = 0, p, s, t;
add_node(root_arr[0].div, 0, 0, doc.Name)
cur_root = root_arr[1].div;
j = doc.Paragraphs.Count;
for(i = 1; i <= j; i++){
para = doc.Paragraphs.Item(i);
window.status = "Parsing paragraph " + i + " of " + j;
if (para.Range.Information(12) == 0){ //paragraph not in table
level = para.OutlineLevel;
s = para.Range.Text;
if (level < 10) { //some heading
if (do_markup == 1){ //need to add bookmarks in source doc
para.Range.Bookmarks.Add("b" + i);
}
if (level != cur_lev){
if (level <= cur_lev) { // not a child of current root
for(k = root_arr.length - 1; level <= root_arr[k].lvl; k--){ //searching for nearest parent
root_arr.length = k + 1;
}
}
if (level > cur_lev) { //child of previous header
k = root_arr.length - 1; //latest
}
cur_root = root_arr[k].div;
}
add_node(cur_root, i, level, s);
cur_lev = level;
}
else { //text
if (s.length > 0){
p = document.createElement("p");
t = document.createTextNode(s);
p.appendChild(t);
root_arr[root_arr.length - 1].div.appendChild(p); //appending to last header
}
}
}
else { //in table
i = add_table(i, root_arr[root_arr.length - 1].div);
}
}
}
function add_table(ii, parent){
var wtable, s, rows, cols, p, r;
var tr, td, t, i = 0, j = 0, k = 1, m = 0, n = 0;;
var div;
active_table++;
div = document.createElement("span");
wtable = doc.Tables.Item(active_table);
ii += wtable.Range.Paragraphs.Count;
cols = wtable.Columns.Count;
rows = wtable.Rows.Count;
s = "<table cellpadding = \"0\" cellspacing = \"0\" border = \"1\">";
for(i = 0; i < rows; i++){
s += "<tr>";
for(j = 0; j < cols; j++){
s += "<td>";
r = wtable.Range.Cells(k).Range.Text;
r = r.replace(/\r\x07/, ""); //Word cell end marks
r = r.replace(/\r|\n/g, "<br/>");
s += r;
s += "</td>";
k++;
}
s += "</tr>";
}
s += "</table>"
div.innerHTML = s;
parent.appendChild(div);
return(ii);
}
function collapse_tree(x){
var xdiv = document.getElementById("d" + x), s, p;
if (header_arr[x].collapsed == 0){
xdiv.style.display = "none";
s = "[ + ]";
}
else {
xdiv.style.display = "block";
s = "|/ - /";
}
header_arr[x].collapsed = Math.abs(header_arr[x].collapsed - 1);
p = document.getElementById(x).childNodes[0];
s = document.createTextNode(s);
p.replaceChild(s, p.childNodes[0]);
}
function help(){
var s;
s = "This app allows to generate CSV files compatible with Test Link Requirements and Test Cases formats from structured MS Word documents.\n"
s += "Word Heading style paragraphs will become headlines, underlaying text will be Requirement body or Test Case Summary section.\n"
s += "Simple tables and paragraphs will be prevented. To prevent Word Auto-Numbered paragraphs, \"Convert Numbers to Text\" checkbox should\n"
s += "be checked before parsing the document. Irregular tables (with merged cells) can be corrupted.\n\n"
s += "Requirements/Test Case bodies will include hyperlinks to corresponding bookmarks (anchors) in the source document if \"Insert Bookmarks\"\n"
s += "checkbox is checked before parsing the document. Proper HTTP path should be set. After that source documents (preferrably converted to\n"
s += "HTML) can be uploaded to TestLink server and accessed directly by bookmark.\n\n"
s += "Checkboxes at each heading paragraph allow to select which headlines will be included in the CSV file.\n\n"
s += "Do not open Word documents which are already open, close them before parsing."
alert(s);
}
</script>
</html>
Contribution: New Word to CSV converter
-
- TestLink user
- Posts: 5
- Joined: Fri Feb 09, 2007 10:59 pm
question
thank you for the tool, but when i try it, i got an error "Automationserver can't create object"
is there any setting need to be done?
is the work doc need to have certain format, in order to be able to convert to csv format?
thank you =)
is there any setting need to be done?
is the work doc need to have certain format, in order to be able to convert to csv format?
thank you =)
Testlink 1.7
Hello,
Is it your tool is compliance with Testlink 1.7 R.C.1 ?
Do you have a Word example file ?
BR
JLAVIGNE
Is it your tool is compliance with Testlink 1.7 R.C.1 ?
Do you have a Word example file ?
BR
JLAVIGNE