6

I wanted to ask how can I view an Excel file from a Mathematica notebook and modify it.

I have seen a similar question, Open Excel file with Mathematica, but the answer involves .NET. Is there any other way to open an Excel file and modify it?

Jennifer
  • 953
  • 4
  • 16

2 Answers2

8

Amending the file directly would indeed require something like .Net. If you were willing to consider an import-export roundtrip but with a spreadsheet like interface in Mathematica, then something like this might work:

rawdata = (Import["myspreadsheet.xlsx"][[2]]);
 (* where 2 is the number of the worksheet you want to use *)
newdata = TableView[rawdata]

Now, change the data cells you want to change and then type Shift-Enter when the cursor is in that TableView.

Then in another cell, evaluate:

newnewdata = %[[1]]

This will give you an expression with the list of changed data, stripped of the enclosing TableView Head.

You can then Export that changed expression back to Excel if that is what you wish.

Verbeia
  • 34,233
  • 9
  • 109
  • 224
3
Row[{
 Button["Browse", (g = SystemDialogInput["FileOpen"]; SystemOpen[g]), Method -> "Queued"],    
 Button["Import", y = Import[g, "Data"]]}]

I have made two Buttons, one for browsing theExcel file and other imports it.

Vitaliy Kaurov
  • 73,078
  • 9
  • 204
  • 355
Jennifer
  • 953
  • 4
  • 16