Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8033365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:40:34+00:00 2026-06-05T01:40:34+00:00

i am trying to write excel file through erlang. I used the following code

  • 0

i am trying to write excel file through erlang. I used the following code to write the excel file

-module(excel).
-export([start/1]).

start(Val)->
        case  file:open("office-test.xls",[append]) of
        {ok,Fd} -> io:format(" file created"),
                io:fwrite(Fd,"~p\t~p\t~p~n", ["Name","Date","Number"]),
                export(Fd,Val),
                file:close(Fd);
        {error,_} ->  io:format("~nerror in creation of file")
        end.


export(_,0)->
        ok;

export(Fd,Val) ->
        io:fwrite(Fd, "~p\t~p\t~p\t~n" ,["B123","2012/10/11 12:12:12","val"++integer_to_list(Val)]),
        export(Fd,Val-1).

It was able to write successfully but when i open in LibreOffice. I got up a pop-up window asking the data seperated by. I dont want the end user to work on it.

1) Is there any way such that the office(ms office or libre office) will automatically parse it.??

2) Is there any other way to write the excel sheets through erlang..??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:40:34+00:00Added an answer on June 5, 2026 at 1:40 am

    you have to write a CSV , Comma delimited text file. You would have to save it with .csv file extension. You write to this file line, by line. make sure that each line ends with \r\n. This file can be read very well from excel.

    You make sure that the headings appear on the first line, like this:

    Name,Sex,Project\r\n
    Joe Armstrong,Male,Erlang\r\n
    Klacke Wickstrom,Male,Yaws\r\n
    Rusty R,Male,Nitrogen\r\n
    Bill Gates,Male,\r\n
    Muzaaya Joshua,Male,ZeePay\r\n
    

    Also, the file encoding matters. ANSI encoding is better. You can as well process Excel files in Erlang by first converting/re-saving the file as .csv , comma delimited file using excel.
    Then use this csv file parser module

    %%% --- csv parser in Erlang. ------
    %%% To help process large csv files without loading them into
    %%% memory. Similar to the xml parsing technique of SAX
    -module(csv). -compile(export_all).
    parse(FilePath,ForEachLine,Opaque)-> case file:open(FilePath,[read]) of {_,S} -> start_parsing(S,ForEachLine,Opaque); Error -> Error end.

    start_parsing(S,ForEachLine,Opaque)-> Line = io:get_line(S,''),
    case Line of eof -> {ok,Opaque}; "\n" -> start_parsing(S,ForEachLine,Opaque); "\r\n" -> start_parsing(S,ForEachLine,Opaque); _ -> NewOpaque = ForEachLine(scanner(clean(clean(Line,10),13)),Opaque), start_parsing(S,ForEachLine,NewOpaque) end.
    scan(InitString,Char,[Head|Buffer]) when Head == Char -> {lists:reverse(InitString),Buffer}; scan(InitString,Char,[Head|Buffer]) when Head =/= Char -> scan([Head|InitString],Char,Buffer); scan(X,_,Buffer) when Buffer == [] -> {done,lists:reverse(X)}. scanner(Text)-> lists:reverse(traverse_text(Text,[])).
    traverse_text(Text,Buff)-> case scan("",$,,Text) of {done,SomeText}-> [SomeText|Buff]; {Value,Rem}-> traverse_text(Rem,[Value|Buff]) end.
    clean(Text,Char)-> string:strip(string:strip(Text,right,Char),left,Char).

    How to use this module to parse csv files from Excel. An example of our simple csv file above, in shell

    C:\Windows\System32>erl
    Eshell V5.9  (abort with ^G)
    1> ForEachLine = fun(Line,Buffer)-> io:format("Line: ~p~n",[Line]),Buffer end.
    #Fun<erl_eval.12.111823515>
    2> InitialBuffer = [].
    []
    3> csv:parse("E:/erlang_projects.csv",ForEachLine,InitialBuffer).
    Line: ["Name","Sex","Project"]
    Line: ["Joe Armstrong","Male","Erlang"]
    Line: ["Klacke Wickstrom","Male","Yaws"]
    Line: ["Rusty R","Male","Nitrogen"]
    Line: ["Bill Gates","Male",[]]
    Line: ["Muzaaya Joshua","Male","ZeePay"]
    {ok,[]}
    4> ForEachLine2 = fun(Line,Buffer)-> io:format("Line: ~p~n",[Line]),[Line|Buffer] end.
    #Fun<erl_eval.12.111823515>
    5> csv:parse("E:/erlang_projects.csv",ForEachLine2,InitialBuffer).
    Line: ["Name","Sex","Project"]
    Line: ["Joe Armstrong","Male","Erlang"]
    Line: ["Klacke Wickstrom","Male","Yaws"]
    Line: ["Rusty R","Male","Nitrogen"]
    Line: ["Bill Gates","Male",[]]
    Line: ["Muzaaya Joshua","Male","ZeePay"]
    {ok,[["Muzaaya Joshua","Male","ZeePay"],
         ["Bill Gates","Male",[]],
         ["Rusty R","Male","Nitrogen"],
         ["Klacke Wickstrom","Male","Yaws"],
         ["Joe Armstrong","Male","Erlang"],
         ["Name","Sex","Project"]]}
    6>
    

    So you can use this module later on to parse your csv files from Excel as well. Now, just learn how to write a csv file line by line, read the pragmatic Erlang Programming Book in the files chapter, or the erlang documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to open a write-protected ms excel 2007 file using win32com in python
I am trying to use the following code to write data into an excel
I am trying to export a datagrid to a an excel file. It converts
I am trying to write and read a password protected excel file, I found
I' trying to write an xml file from Excel VBA using Microsoft XML 6.0.
I'm trying to write an excel file from php, and I need that some
I'm trying to write data to an excel file that includes Japanese characters. I'm
I'm trying to write a file using VBA. My code is below. It worked
I am trying to write a small web tool which takes an Excel file,
I'm trying to write a stored procedure that will read an Excel file into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.