6
$\begingroup$

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?

$\endgroup$
10
  • $\begingroup$ You could Import[] a spreadsheet, but I don't believe there's a native way to have a spreadsheet interface within Mathematica... $\endgroup$ Commented Jul 5, 2012 at 7:00
  • $\begingroup$ @J.M. well there is TableView ... $\endgroup$
    – Mr.Wizard
    Commented Jul 5, 2012 at 7:04
  • $\begingroup$ @J.M.: I dont want to import the values because I want that end user can open the Excel file and change its values if needed and then use it in application. $\endgroup$
    – Jennifer
    Commented Jul 5, 2012 at 7:06
  • $\begingroup$ @Mr.Wiz, undocumented, I see... :) $\endgroup$ Commented Jul 5, 2012 at 7:06
  • 1
    $\begingroup$ Then I don't quite understand why you want to use Mathematica to open Excel files... something about "use the proper tool for the job"? $\endgroup$ Commented Jul 5, 2012 at 7:07

3 Answers 3

8
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ TableView has some useful column sorting capabilities. $\endgroup$ Commented Jul 5, 2012 at 9:34
  • $\begingroup$ @Verbeia: Thanks...but I have tried it in another way. I have posted my answer. $\endgroup$
    – Jennifer
    Commented Jul 6, 2012 at 7:07
3
$\begingroup$
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.

$\endgroup$
0
$\begingroup$

While this doesn't allow you to edit the spreadsheet in Mathematica directly per se, I did make a resource function a few months ago which allows you to edit any 2D arrays in your system's native spreadsheet editor. The resource function is called SpreadsheetEdit and it can be accessed on the Wolfram Function Repository https://resources.wolframcloud.com/FunctionRepository/resources/SpreadsheetEdit/

And used in Mathematica as ResourceFunction["SpreadsheetEdit"][data]

enter image description here

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.