sc: the Venerable Spreadsheet Calculator

 in
If you like vi, and you like the command line, you will love sc—a spreadsheet that runs in a terminal.
Conclusion

Linux users have many options for spreadsheets, not to mention Web-based ones, including Google Docs spreadsheets. But, most people probably would be stumped if asked for a spreadsheet that can be used in a terminal. sc is one of the oldest FOSS spreadsheets. It's been available for more than 20 years, and it's terminal-based, with keybindings that should be familiar to any vi user. It supports advanced macros, plugins and external functions, and it can export to its own format, plain text, LaTeX or CSV for easy input to other spreadsheets.

Serge Hallyn is a Linux developer with Canonical. Over the years, he's been involved with containers, SELinux and POSIX capabilities.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Code patch with indentation corrected

Ronald Greenberg's picture

Oops, I didn't realize the code would be reformatted. Should have used the right HTML tags to keep the indentation:

        col = letters[column]
        if len(p) != 0:
            try:
                n = string.atof(p)
                text.append('let %c%d = %g' % (col, row, n))
            except:
                if p[0] == '"':
                    text.append('label %c%d = %s' % (col, row, p))
                else:
                    text.append('label %c%d = "%s"' % (col, row, p))
        column += 1

Improvement to script for empty cells

Ronald Greenberg's picture

The script skips over empty cells as if they didn't exist. It's fine to not put anything in the .sc file for an empty cell, but one should move over to the next column so that empty cells are preserved. A fix is to replace the body of the "for p in allp" with this:
col = letters[column]
if len(p) != 0:
try:
n = string.atof(p)
text.append('let %c%d = %g' % (col, row, n))
except:
if p[0] == '"':
text.append('label %c%d = %s' % (col, row, p))
else:
text.append('label %c%d = "%s"' % (col, row, p))
column += 1
(I've aso applied the fix suggested in the previous comment.)

R.

Great article. Problem in Python script:(

dfranz's picture

Just on the day I started exploring sc on my Nanonote,
which was highligted in the same issue, I discovered this
really helpful article via web search. When my October
issue came in, I'm sure I saw the article, but it did
not catch my attention then:)

My quick review of sc revealed that there was no feature
to import from other formats. The Python script looked
like it solved the problem, but on my first test I found
that it treated all numbers containing a decimal point
as labels--not what I wanted. Changing the call
to string.atol() to string.atof() and changing
the format "let %c%d = %d' to 'let %c%d = %g'
solved the problem.

Now on to exploring sc on the Ben Nanonote. Thanks
for a timely article.

Delbert

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix