Python Forum
Excel from SAP - dealing with formats and VBA
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Excel from SAP - dealing with formats and VBA
#1
Hello,

I'm working on automatizing one report using Python.
In general I have around 20 excel files (.xlsx and .xlms) that I filter base on some criteria and then copy&paste to final report. At the end I dropdown/autofill formulas in the final report (from first row till end) - I assume it will save some time in preparing report.

Is there any library/solution of copy&pasting data including formats? I have .xlsm file from SAP. In one column I have data that I need to extract (KG, PCs, EUR, USD ect). In "normal" process I copy&paste data to separte sheet and then use macro. I cannot use macro in original file as it has some "dummy" VBA code inside.
Also copy&paste solution with Python doesn't work as it miss formats between the files..
Reply
#2
Quite a lot of people seem to want to know how to get things from Excel, but they don't want to share what they have.

Nuclear Secrets!

You can check the openpyxl documentation here.

Or you could post a small example Excel file, then no one has to guess what you may, or may not, have.

Then you just need to make clear what, exactly, it is that you want to achieve, assuming you are clear about that.

Or, this 1-liner:

from magic import wand

resultXL = wand.wave("my_old_ excel", "my_total_solution_excel")
Big Grin Big Grin Big Grin
Reply
#3
What I want to achive:
Either
1. Copy and paste data including formats into main report file. Next extracting format (KG, PCs, EUR, USD ect) in separate column
or
2. Extracting format (KG, PCs, EUR, USD ect) in separate column in source excel. Next copy and paste data into main report file.
or
3, Whatever activities that can be done to have data with extracted forma in main report file.


I'm testing possibilities using openpyxl using this documentation but without success.

Is there any additional information that would you like to have?




(Feb-23-2024, 01:05 PM)Pedroski55 Wrote: Quite a lot of people seem to want to know how to get things from Excel, but they don't want to share what they have.

Nuclear Secrets!

You can check the openpyxl documentation here.

Or you could post a small example Excel file, then no one has to guess what you may, or may not, have.

Then you just need to make clear what, exactly, it is that you want to achieve, assuming you are clear about that.

Or, this 1-liner:

from magic import wand

resultXL = wand.wave("my_old_ excel", "my_total_solution_excel")
Big Grin Big Grin Big Grin

Attached Files

.xlsx   test.xlsx (Size: 9.46 KB / Downloads: 12)
Reply
#4
Interesting, but not so challenging: your test.xlsx has 2 sheets, Sheet1 and Sheet2

Rows 1 and 2 of column A contain 2 4 digit numbers marked with an apostrophe, which marks them as strings, I believe.

A quick look tells me, this file contains no other data. Maybe you are CIA?

Either, these are coded Nuclear Secrets, masquerading as default formatted numbers or:

What do you want to do with this "data"?
Reply
#5
(Feb-23-2024, 03:34 PM)Pedroski55 Wrote: What do you want to do with this "data"?

Answer is in post above....

What I want to achive:
Either
1. Copy and paste data including formats into main report file. Next extracting format (KG, PCs, EUR, USD ect) in separate column
or
2. Extracting format (KG, PCs, EUR, USD ect) in separate column in source excel. Next copy and paste data into main report file.
or
3, Whatever activities that can be done to have data with extracted forma in main report file.


I've tested copy&pasting -> it didn't work for me to keep format. If I do this I somehow "destroy" main report file. I cannot open it after launching Python script.
Launching VBA in original file to extract format (KG, PCs, EUR, USD ect) - not working due to already existing VBA code that stops using own VBA.

Questions?
Reply
#6
You want to write a programme to copy 4 default-formatted numbers from an Excel file to another Excel file?

Excuse me, but I hardly think such an effort is required, or worthwhile!

But if you look at the docs of openpyxl, they will show you how to do that quite easily.
Reply
#7
(Feb-23-2024, 04:53 PM)Pedroski55 Wrote: You want to write a programme to copy 4 default-formatted numbers from an Excel file to another Excel file?

Excuse me, but I hardly think such an effort is required, or worthwhile!

But if you look at the docs of openpyxl, they will show you how to do that quite easily.

First of all, provided file is a sample file. In process I have 3 files 40000 rows each.

Secondly, if I managed to work out something using docs of openpyxl I wouldn't post question on this forum.
Reply
#8
I'm sure there are a lot of people here who would like to help you, including me, but you really need to give us something to work with.

I don't want to guess what you have, where and how to get it, that makes it difficult to try things and difficult to help you.

People here have said they have 20GB Excel files to operate on! You don't need to post 20GB, even if you could!

You do not need to post 40000 rows, just enough for people to get a good idea of what you have. 100 rows is probably enough.

Help people to help you!

In openpyxl you just loop through the rows and columns searching for whatever it is you want and putting that data somewhere else. It's not rocket science!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  UnicodeEncodeError - Dealing with Japanese Characters fioranosnake 2 2,495 Jul-07-2022, 08:43 PM
Last Post: fioranosnake
  Dealing with duplicated data in a CSV file bts001 10 11,577 Sep-06-2021, 12:11 AM
Last Post: SamHobbs
  [split] NameError: name 'formats' is not defined shobhu123 1 4,010 May-24-2020, 06:29 PM
Last Post: Skaperen
  Need help working with two excel file with different formats mikey3580 1 1,609 Apr-22-2020, 07:11 AM
Last Post: DPaul
  Dealing with a .json nightmare... ideas? t4keheart 10 4,415 Jan-28-2020, 10:12 PM
Last Post: t4keheart
  How to convert different timestamp formats? python_newbie09 12 6,911 Aug-05-2019, 06:37 PM
Last Post: python_newbie09
  Dealing with Exponential data parthi1705 11 9,821 May-30-2019, 10:16 AM
Last Post: buran
  Dealing with multiple context managers heras 5 4,727 Nov-16-2018, 09:01 AM
Last Post: DeaD_EyE
  How to generate calendar with 2 formats in python luizcrf 1 2,678 Nov-01-2018, 06:46 AM
Last Post: Larz60+
  dealing with big data of timestamp LMQ 0 2,180 Jul-27-2018, 01:23 PM
Last Post: LMQ

Forum Jump:

User Panel Messages

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