Python Forum
Convert Excel file into csv with Pipe symbol..
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert Excel file into csv with Pipe symbol..
#1
Hi Team,

I have excel file, I want to read that excel file and save it into csv files.
But delimiter I expect "|" symbol instead of comma,


1) In Data.xlsx workbook, ----, Select sheet named "Recon"
2) select range from "A10:Z10000" or till last row of data. ( Indirectly skip top rows.)
3) Create a csv file for only that range. with delimiter "|"
4) Output file name should be Recon.csv


Finally I want to insert those records into SQL Table. was my intention.
Reply
#2
What have you written so far? Please share, working or not.
Reply
#3
Do you need to generate the csv file? Sounds like that is an intermediate step that you can probably skip.

Look at https://docs.python.org/3/library/csv.html

It is obvious how you set the separator for csv readers and writers.
Reply
#4
Maybe you just really want to do this with Python, but it seems to me a very easy thing to do manually: Let PHP do the work!

The table you want to import into must of course exist and have the correct number of columns. (The same number as your XL, or vice-versa.)

1. Open your XL and save as csv. (If you really need a | as separator, can't see why, you can set that then.)
2. In phpMyAdmin, import the csv, entering the number of rows you want to skip under Partial Import

Conflicting IDs as Unique key will cause problems.

If you already have data in the table you don't want to repeat, click: "Update data when duplicate keys found on import (add ON DUPLICATE KEY UPDATE)"

Quick, easy, hassle free!
That way, you'll have more time to spend with the gf!
Reply
#5
This is a simple task in python
  • load the excel 'recon' sheet using pandas see: pandas.read_excel
    look at examples at bottom of page.
  • write pandas frame: see DataFrame.to_csv
    look at attribute " sep='|' " (on same document page) to set your separator.

there are only 3 (4 if you make cell selection a separate line) lines of code necessary

  1. import pandas
  2. load the excel page
  3. write selected cells to the csv page

That's it
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python openyxl not updating Excel file MrBean12 1 315 Mar-03-2024, 12:16 AM
Last Post: MrBean12
Question [SOLVED] Correct way to convert file from cp-1252 to utf-8? Winfried 8 796 Feb-29-2024, 12:30 AM
Last Post: Winfried
  Copy Paste excel files based on the first letters of the file name Viento 2 423 Feb-07-2024, 12:24 PM
Last Post: Viento
  Decryption not working if key has same symbol like text Paragoon2 0 310 Nov-11-2023, 09:32 PM
Last Post: Paragoon2
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,429 Nov-09-2023, 10:56 AM
Last Post: mg24
  Search Excel File with a list of values huzzug 4 1,216 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Updating sharepoint excel file odd results cubangt 1 821 Nov-03-2023, 05:13 PM
Last Post: noisefloor
  Convert File to Data URL michaelnicol 3 1,150 Jul-08-2023, 11:35 AM
Last Post: DeaD_EyE
  Python Script to convert Json to CSV file chvsnarayana 8 2,496 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,089 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020