-2

I want to create excel sheet from the 2-dimensional array.

I apologie for demanding code from scratch.

    function downloadableCSV(rows) {
      var content = "data:text/csv;charset=utf-8,";

      rows.forEach(function(row, index) {
        content += row.join(",") + "\n";
      });

      return encodeURI(content);
    }

    var rows = [
      ["name1", 2, 3],
      ["name2", 4, 5],
      ["name3", 6, 7],
      ["name4", 8, 9],
      ["name5", 10, 11]
    ];

    $(document).ready(function(){
        $("#download").click(function() {
          downloadableCSV(rows);
        });

    });

I got this code from others fiddle. For any reason, the code seems not working.

Any help will be greatly appreciated. Thanks.

0

2 Answers 2

-1

You can use ExcelPlus api. Just add two lines to call the necessary files:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/CHOOSE_A_VERSION/xlsx.core.min.js"></script>
<script type="text/javascript" src="excelplus-2.5.min.js"></script>

An example about how to write/create an Excel file:

// --- EXAMPLE 1 ---
// in this example we want to build an Excel file with one sheet and write some stuff
var ep=new ExcelPlus();
// We're going to do several tasks in one line of code:
// 1) create an Excel with one sheet called "Book1"
// 2) write some data from an array to the new-created sheet
// 3) create a new sheet called "Book2"
// 4) write "A1" in cell "A1" of the new-created sheet
// 5) write the today date in D1 of the "Book1" sheet
// 6) save it on the user computer (this last step only works with IE10+ and modern browsers)
ep.createFile("Book1")
  .write({ "content":[ ["A1","B1","C1"] ] })
  .createSheet("Book2")
  .write({ "cell":"A1", "content":"A1" })
  .write({ "sheet":"Book1", "cell":"D1", "content":new Date() })
  .saveAs("demo.xlsx");
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your answer. i have updated my question, can you correct me there plz.
-2

You cannot create Excel files manually. But you can create .csv files which can be read by Excel. Have a look at this post.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.