Quick spreadsheet viewer in vanilla JS

Overview

Heihō

Quick spreadsheet viewer in vanilla JS

Heihō

What it does ?

The heiho.js script is quick and simple spreadsheet viewer. It is meant to preview the contents of csv files inside your browser without needing any other tools. It uses plain vanilla javascript so it has no dependencies, but for the applied styling from the css file.

This is not a spreadsheet editor, this is a preview tool only.

How to use ?

Simply include both the javascript file and the css stylesheet in your HTML document. It's best if you put them at the bottom, close to the closing <\body> tag.

<link rel="stylesheet" href="/path/to/heiho.css" />
<script src="/path/to/heiho.js"></script>

Or include it via jsDelivr CDN:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kktsvetkov/heiho@latest/heiho.css" />
<script src="https://cdn.jsdelivr.net/gh/kktsvetkov/heiho@latest/heiho.js"></script>

Once included in your document, simply call Heiho() and pass the data as argument

var data = [ ['a', 'b', 'c'], [1,2,3], [4,5,6] ];
Heiho(data);

You can modify some of the output using a second argument that passes additional options

Heiho(data, {max:20}); // shows only 20 rows from data

Explore more cases in the examples section below.

Options

There is a small set of options used to influence the output of the spreadsheet preview.

  • options.header is boolean value whether to style the first row in the
    preview differently; this meant to be used with CSV files, where the first row holds the column titles; default value is null which triggers an attempt to auto-detect whether the first row is header or not.

  • options.max is an integer value that restricts how many rows to be included in the preview; you can use 0 to disable it, and its' default value is 100.

  • options.title this is used to output the header title; you can use a string to just pass a text to be inserted there, or you can use a function that manipulates the HTML element that is the header title (look in the examples below)

  • options.truncate is a function used to render the output in the "truncate" element of the preview; this element appears if the rows of the data previewed are more than options.max as an acknowledgement that the data was truncated (look in the examples below to see how this work)

Options are passed as a second argument to Heiho() function.

Heiho(data, { max: 20, title: 'proba.csv' });

You can add more elements to the options argument which you can later use in some of the functions inside it such as options.title and options.truncate.

Examples

Let's explore few examples of what you can do with Heihō

Title

You can modify what is rendered in the header title of the preview. The basic approach here is to just pass the title as a string in the options, like this:

Heiho(data, { title: 'users.csv' });

You can also do more with it if you pass a function as the title. In that case it will be executed to populate the contents of the header title will be. The arguments are the header title element, and the options used.

var file = {filename: 'Proba.csv', size: '123KB', created: '2009-08-21 14:01:36'}
Heiho(data, { title: function(el, o)
	{
		el.innerHTML = '<b>'
			+ file.filename + '<\/b> <code>'
			+ file.size + '<\/code> '
			+ file.created;
	}
});

Truncate

Similar to how options.title is used as a function, options.truncate is used to populate the contents of the "truncate" element (the warning shown when there are more rows to preview than the options.max restriction). This function gets more arguments:

/**
* @param {DomElement} el the truncate element
* @param {Integer} max
* @param {Array|Object} data data previewed
* @param {Object} o options
*/
options.truncate = function(el, max, data, o)
{
	el.innerHTML = 'Showing only first ' + max + ' rows';
	el.style.display = '';
}

Papa Parse

You can use the popular Papa Parse (github) library to parse CSV data inside your browser. You can use it together with Heihō to preview the result from the CSV parsing

Papa.parse(file, {
	complete: function(results) {
		Heiho(results.data);
	}
});

Explore all the examples on papaparse.com, they are a blast!

Here's an example of Papa Parse and Heiho previewing a remote csv file:

Papa.parse("http://example.com/file.csv", {
	download: true,
	complete: function(results) {
		Heiho(results.data);
	}
});
You might also like...

🔆🔎👀 Smart Contract Storage Viewer, DataType Guesser, Toolbox & Transaction Decoder

🔆🔎👀  Smart Contract Storage Viewer, DataType Guesser, Toolbox & Transaction Decoder

🔆 🔎 👀 Smart Contract Storage HexViewer Demo Target - the target contract API Endpoint - your infura (or equivalent) api key Retrieves smart contrac

Nov 27, 2022

This is an IFC wrapped on Three js based viewer, I think..

This is an IFC wrapped on Three js based viewer, I think..

ifc-three-js-viewer Project description: This is an IFC wrapped on Three js based viewer, I think.. Features & Screenshots: A simple viewer for render

Dec 14, 2022

A Simple Text/Document Viewer written in JS

A Simple Text/Document Viewer written in JS

Doku Doku.js is a terminal ui text/document viewer that supports a custom documentation syntax called doky. Features Border colors. (all common termin

Sep 9, 2022

A viewer for Arc System Works scripts and hitboxes written in Godot.

A viewer for Arc System Works scripts and hitboxes written in Godot.

ASWViewer A viewer for Arc System Works scripts and hitboxes written in Godot. Currently only supports Guilty Gear -Strive-. It also displays the mode

Sep 20, 2022

This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js

This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js. But in most cases, I would recommend you to use something like Express in a production project for productivity purposes.

Jul 19, 2022

An easy-to-read, quick reference for JS best practices, accepted coding standards, and links around the Web

An easy-to-read, quick reference for JS best practices, accepted coding standards, and links around the Web

Feel free to contribute! Where? http://www.jstherightway.org Why? Today we have a bunch of websites running JavaScript. I think we need a place to put

Jan 1, 2023

A quick capture plugin for Obsidian, all data from your daily notes.

A quick capture plugin for Obsidian, all data from your daily notes.

Obsidian Memos 中文文档 A new way for you to quick capture an idea in Obsidian. Which is highly based on the awesome open source project: memos and awesom

Jan 3, 2023

A quick start Create React App template with react-router-dom, material-ui, gh-pages and firebase

A quick start Create React App template with react-router-dom, material-ui, gh-pages and firebase. With google authentication, routing and deployment capabilities built in.

Feb 22, 2022

This app offers users a quick way to check the current temperature and humidity of any location in the world.

This app offers users a quick way to check the current temperature and humidity of any location in the world.

Pretty Weather App This app offers users a quick way to check weather data for any location in the world. The specific data provided by the app includ

Jun 7, 2022
Comments
  • Style

    Style "first row" differently (and probably make it stick with the header)

    This script is previewing only CSVs, not real spreadsheets. In almost all of the CSVs the first row is the header row with the titles of the columns. It makes sense to have it styled differently so that is more obvious that this is the row with the column titles. No need for anything flashy, just making them bold might be enough.

    Considering #3 perhaps this first row must also stick to the top of the preview.

    All of this is best to be configurable through the options so that there is some options flag that instructs the preview whether to treat the first row differently or not. Some research into how this can be auto-detected will probably help with the default behaviour of this setting when nothing explicitly is specified.

    enhancement 
    opened by kktsvetkov 3
  • Calculate column widths

    Calculate column widths

    Resize column widths according to the data that is previewed in them. Without this, the browsers set the column width and wrap some of the content that can be presented on multiple rows. Find a balance where a column is wide enough to show more of the data inside it, but it is not that wide to make the whole preview harder to read.

    Track data length in each column and optimize around median values and not the extremes.

    enhancement wontfix 
    opened by kktsvetkov 1
  • Loading message

    Loading message

    Instead of showing the preview only when the data is fully loaded, try to load the preview first, show a "Loading..." message, and then load the rows. This will help with some big spreadsheets, where now there is some delay between the command is triggered and when the preview is shown.

    Add options function for the contents of the loading element in the same way options.title and options.truncates are used.

    enhancement 
    opened by kktsvetkov 0
Releases(0.3.5)
Owner
Kaloyan Tsvetkov
Author of Krumo, Wano, Asido and few other open-source PHP projects ending in "o"
Kaloyan Tsvetkov
This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreadsheet.

HtmlFormApp Overview This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreads

Kanshi TANAIKE 18 Oct 23, 2022
Embed Luckysheet (spreadsheet) into Logseq.

logseq-plugin-luckysheet 在 Logseq 中嵌入电子表格 Luckysheet。你也可以用它来维护一张 markdown 表格。 Embed Luckysheet (spreadsheet) into Logseq. You can also use it to maint

Seth Yuan 49 Jan 1, 2023
An opensource 360° media viewer written in JavaScript using Electron and Marzipano

open360viewer open360viewer is an opensource 360° media viewer. It is based on electron and marzipano. It currently supports opening equirectangular 3

null 4 Oct 9, 2022
An alternative viewer for DevDAO NFT with a ✨holographic✨ twist

Holo DevDAO An alternative viewer for DevDAO NFT with a ✨ holographic ✨ twist. Pre-requisites node version >= 15.0.1 & npm >= 7.20.6. If you have nvm

Naomi Hauret 19 Dec 17, 2022
A Web Viewer for Blender.

BlenderWebViewer a Web Viewer for Blender. To get started: Clone the repo Install the add-on for Blender (blenderPlugin.zip) change the path field in

eliaorsini 48 Nov 29, 2022
[ThatProject] ESP32 LoRa GPS Data Viewer

Map Viewer for MCU with LoRa & GPS Data ThatProject Channel LoRa module has caught the attention of many people for a number of reasons. Being able to

Eric 6 Aug 7, 2022
Custom Element: interactive panorama viewer

<little-planet> This project is a Custom HTML Element (AKA Web Component) that renders an interactive view of a panoramic photo. Can be used with no J

Ondřej Žára 12 Nov 25, 2022
JavaScript Online DWG/DXF Viewer

dwg-viewer-js A DWG viewer you can buy for $420 (US) I had originally made this for a software company but they cancelled at the last moment so if any

Savir Singh 4 Jul 6, 2022
Embed panorama photos on your website with Panorama Viewer

#Panorama Viewer by Pete R. Embed interactive Panorama Pictures on your site with this simple plugin. Created by Pete R., Founder of Travelistly and B

Pete R. 474 Oct 8, 2022
An OpenStoriesFeed viewer

An OpenStoriesFeed viewer

ddddddddʣzzz 22 Dec 17, 2022