0
$\begingroup$

I import an excel file

c1  c2  c3
1   3   5
2   4   6


fp = NotebookDirectory[] <> "Book1.xls";

excelSheet = Import[fp] [[1]];
t1 = Grid[excelSheet, Frame -> All, Alignment -> Left,
  Background -> {None, {Gray, {White, LightGray}}}

The table shows each number with a "." at the end :( How do I get rid of it?

c1  c2  c3
1.  3.  5.
2.  4.  6.

Thanx

Solution:

For[i = 1, i <= Length[excelSheet], i++,
  For[j = 1, j <= Length[excelSheet[[i]]], j++,
    If[NumericQ[excelSheet[[i, j]]],
      excelSheet[[i, j]] = Round[excelSheet[[i, j]]];
      ];
    ];
  ];
$\endgroup$
9
  • $\begingroup$ what should i do :( ? $\endgroup$
    – TraceKira
    Commented Dec 21, 2014 at 14:34
  • $\begingroup$ do you expect me to read hundred of pages of text for such a simple problem ?! $\endgroup$
    – TraceKira
    Commented Dec 21, 2014 at 14:35
  • $\begingroup$ Please read this: mathematica.stackexchange.com/a/18485/131 $\endgroup$
    – Yves Klett
    Commented Dec 21, 2014 at 14:35
  • 5
    $\begingroup$ Please consider the following a friendly advice. Mathematica is a tough piece of software that demands a lot of effort to tame. Every experienced user already knows and accepts that. When you write "do you expect me to read hundred of pages of text for such a simple problem ?" you should know that everybody out there have already done that, and don't consider it lost time. If you're not predisposed to invest a great deal of effort into Mathematica, don't even try. You'll feel discouraged too soon. $\endgroup$ Commented Dec 21, 2014 at 20:50
  • 2
    $\begingroup$ @TraceKira excelSheet /. x_?NumericQ :> With[{r = Round[x]}, r /; r == x] is more robust, or since it's Excel, x_Real instead of x_?NumericQ. (You might not want to convert 6.4 to 6. This replacement rule will round to an integer only if the rounded value is equal to the original number.) $\endgroup$
    – Michael E2
    Commented Dec 22, 2014 at 3:15

1 Answer 1

7
$\begingroup$

Following discussion with WRI tech support, setting Import's “Numeric” -> False has no effect on Excel files (.xls, .xlsx), but works when importing comma or tab delimited text files (.csv, .tsv).

WRI understands that "this could be very frustrating and inconvenient for you" and apologizes for this but lacks the resources to fix. So either:

(1) convert to csv (which by the way can also be exported via REST from Google gsheets)

(2) Round[] any NumericQ data after Import.

$\endgroup$
3
  • 5
    $\begingroup$ "but lacks the resources to fix." — have you tried telling WRI that you're doing Tweetable data science of the computational world using the Internet of Things in Excel? Maybe you'll get it fixed faster that way ;) $\endgroup$
    – rm -rf
    Commented Dec 21, 2014 at 16:51
  • $\begingroup$ what does it means ? I cannot get rid of points ? $\endgroup$
    – TraceKira
    Commented Dec 21, 2014 at 19:25
  • 3
    $\begingroup$ Anything that they don't intend to fix should be clearly documented as broken. $\endgroup$ Commented Dec 21, 2014 at 22:13

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