T

TechIdea

Ecosystem

Back to Tally Masterclass

How to Automate Excel to Tally Imports

Stop typing manually. Learn how to parse CSV/Excel files using Node.js and automatically inject them into TallyPrime as Sales or Receipt Vouchers.

Why Automate Excel Imports?

Many businesses receive daily Excel or CSV reports—from Amazon seller central, banking statements, or third-party POS systems. Manually entering thousands of rows into Tally is slow and error-prone. By writing a simple script, you can parse the Excel file, convert each row into XML, and push it directly into Tally.

Step 1: Read the CSV in Node.js

We will use the csv-parser and fs modules to read a file named sales.csv.

const fs = require('fs');
const csv = require('csv-parser');

const results = [];

fs.createReadStream('sales.csv')
  .pipe(csv())
  .on('data', (data) => results.push(data))
  .on('end', () => {
    console.log(results);
    // Proceed to Step 2
  });

Step 2: Generate Bulk XML

Instead of sending one request per row, we can combine all vouchers into a single massive XML payload. This is significantly faster.

const generateBulkXml = (rows) => {
  let vouchersXml = '';

  rows.forEach(row => {
    // Assuming CSV headers: Date, Customer, Amount
    const tallyDate = row.Date.replace(/-/g, ''); 
    
    vouchersXml += `<TALLYMESSAGE>
      <VOUCHER VCHTYPE="Sales" ACTION="Create">
        <DATE>${tallyDate}</DATE>
        <VOUCHERTYPENAME>Sales</VOUCHERTYPENAME>
        <PARTYLEDGERNAME>${row.Customer}</PARTYLEDGERNAME>
        
        <ALLLEDGERENTRIES.LIST>
          <LEDGERNAME>${row.Customer}</LEDGERNAME>
          <ISDEEMEDPOSITIVE>Yes</ISDEEMEDPOSITIVE>
          <AMOUNT>-${row.Amount}</AMOUNT>
        </ALLLEDGERENTRIES.LIST>
        
        <ALLLEDGERENTRIES.LIST>
          <LEDGERNAME>Sales Account</LEDGERNAME>
          <ISDEEMEDPOSITIVE>No</ISDEEMEDPOSITIVE>
          <AMOUNT>${row.Amount}</AMOUNT>
        </ALLLEDGERENTRIES.LIST>
      </VOUCHER>
    </TALLYMESSAGE>`;
  });

  return `<ENVELOPE>
    <HEADER><TALLYREQUEST>Import Data</TALLYREQUEST></HEADER>
    <BODY>
      <IMPORTDATA>
        <REQUESTDESC><REPORTNAME>Vouchers</REPORTNAME></REQUESTDESC>
        <REQUESTDATA>
          ${vouchersXml}
        </REQUESTDATA>
      </IMPORTDATA>
    </BODY>
  </ENVELOPE>`;
};

Step 3: Post the Bulk XML

Finally, send the generated XML to Tally's local server port using Axios.

const axios = require('axios');

const postToTally = async (xmlData) => {
  try {
    const response = await axios.post('http://localhost:9000', xmlData, {
      headers: { 'Content-Type': 'text/xml' }
    });
    console.log("Successfully imported rows to Tally!");
  } catch (error) {
    console.error("Failed to import:", error.message);
  }
};

Need a Custom Excel Utility?

Building mapping logic for multi-item invoices with IGST/CGST calculations is complex. We build custom desktop and web-based utilities that map any complex Excel format into Tally instantly.

Growth Newsletter

Get practical AI tools, SEO tips, and growth guides weekly.

Join creators, students, and businesses scaling with TechIdea.