我有面試問題問的Excel格式的輸出爲:
創建使用HTML和JavaScript
寫JS插件,可以採取細胞和值作爲輸入和呈現Excel的瀏覽器的格式輸出。例如,
例輸入(單元格和值):在瀏覽器
J3 = 5
A2 = 20
K1 = 10
輸出應以Excel格式
A B C ....... J K .......
1 10
2 20
3 5
..
我一直在尋找的問題,正確的解決方案。
我試圖解決這個問題(寫psudeo代碼)
var cell = {"J3": 5, "A2":20, "K1": 10}
// Function they will call for generate excel style table
generateExcel(cell, selector) {
1. create blank table which has A-Z column (with selector as A-Z resp) and 1 to 100 rows (with selector as 1 to 100 resp)
2. Loop through each cell and for each cell
2.1 find the column (J) and row (3)
2.2 Add/replace value in that TD
3. Once all the information from cell in enter in table, print the table in the document at given selector
}
他們說,這不會是高效爲單元格輸入數量巨大。我建議我們可以使用Matrix創建表格
A B... J K ....
1 [ 10 ]
2 20
3 5
你有什麼迄今訪問表格單元格?人們應該樂於幫助你優化你的代碼,但如果他們回答你的話,他們不應該得到這份工作=)? – mrtsherman 2012-02-08 03:11:38
你在面試中給了你答案嗎?你有什麼嘗試? – 2012-02-08 03:11:40