views:

47

answers:

1

hello everybody,

I am working on a project where I must export to html a lot of Excel files. This is pretty straightforward using automation and saving as html.

The problem is that many of these sheets have links to worksheets of some other files. I must find a way to write a link to a single inner worksheet.

When you export a multisheet excel file to html, excel creates a main htm file, a folder named filename_file, and inside this folder it writes down several files: a css, an xml list of files, a file that creates the tab bar and several html files named sheetxxx.htm, each one representing a worksheet.

When you open the main file, you can click the menu bar at the bottom which lets you select the appropriate sheet. This is in fact a link, which replaces a frame content with the sheetxxx.htm file. When this file is loaded a javascript function that selects the right tab gets called.

The exported files will be published on a web site. I will have to post process each file and replace every link to the other xls files to the matching htm file, finding a way to open the right worksheet.

I think that I could add a parameter to the processed htm file link url, such as myfile.htm?sh=sheet002.htm if I want to link to the second worksheet of myfile.htm (ex myfile.xls). After I've exported them, I could inject a simple javascript into each of the main files which, when they are loaded, could retrieve the sh parameter with jQuery (this is easy) and use this to somehow replace the frSheet frame contents (where the sheets get loaded), opening the right inner sheet and not the default sheet (this is what I call deep linking) mimicking what happens when a user clicks on a tab.

This last step is missing... :) I am considering different options, such as replacing the source of the $("frSheet") frame after document.ready.

I'd like to hear from you any advice on what could be the best way to realize that in your opinion.

any help is greately appreciated, many thanks.

A: 

mmh maybe I've found a way that works, after all. using some code from http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html to get the passed parameter, I've written a very simple code to substitute the fsSheet frame src:

    function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

$().ready(function () {

    var id = getUrlVars()["id"];

    if (id != null) {
        //  document.location = id;
      var fr= $("frame")[0];
      fr.src=id;
    }

});

the file must be called as in:

Cartel1.htm?id=cartel1_file/sheet003.htm

to select the third sheet. this seems to work in IE, FFox and Chrome.

If you have any better idea, please let me know.

pomarc