1 year ago
#270127
Sudhanshu Sharma
Is there any way to extract data from text file in Excel through python?
Iam new to Python so completing my task is always a big hassle for me. I do try a lot of things but generally get stuck .So I hope that someone could assist me.
There is one procedure with humungous line of code . I want to make table out of it that I can use for my further coding .
--Product1--
begin
insert into crs_daily_production_data select :I_DT,3,3,21,'A01',
NVL(A1_506,0),NVL(A1_507,0),NVL(A1_508,0) FROM DAILYTECH_OUTPUT
WHERE DATA_DATE=:I_DT;
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
SELECT NVL(A1_506,0),NVL(A1_507,0),NVL(A1_508,0) INTO V_PROD,V_MPROD,V_YPROD
FROM DAILYTECH_OUTPUT
WHERE DATA_DATE=:I_DT;
UPDATE crs_daily_production_data SET
DAILY_QTY=V_PROD,CUM_MONTHLY_QTY=V_MPROD,CUM_YEARLY_QTY=V_YPROD
WHERE DT=:I_DT AND UNIT_CD=3 AND PLANT_CD=3 AND PRODUCT_CD='A01' AND STREAM_CD=21;
END ;
--Product2
begin
V_PROD:=0;V_MPROD:=0;V_YPROD:=0;
insert into crs_daily_production_data select :I_DT,3,702,21,'A02',
NVL(A2_506,0),NVL(A2_507,0),NVL(A2_508,0) FROM DAILYTECH_OUTPUT
WHERE DATA_DATE=:I_DT;
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
SELECT NVL(A2_506,0),NVL(A2_507,0),NVL(A2_508,0) INTO V_PROD,V_MPROD,V_YPROD
FROM DAILYTECH_OUTPUT
WHERE DATA_DATE=:I_DT;
UPDATE crs_daily_production_data SET
DAILY_QTY=V_PROD,CUM_MONTHLY_QTY=V_MPROD,CUM_YEARLY_QTY=V_YPROD
WHERE DT=:I_DT AND UNIT_CD=3 AND PLANT_CD=702 AND PRODUCT_CD='A02' AND STREAM_CD=21;
END ;
Above Code is example of 2 product where with some condition, data is saved into pre defined table. I want to make new table and it should have columns like(all these data is available in the TXT file) Product // Data Table// Column Name (i.e. A1_506) // Data table(if value available)//Plant Code/Unit Code//StreamCode etc where I can use this table in loop and optimize that procedure in for future working.
Is there any way I can do this efficiently as I don't want to copy paste data for 4k rows manually.
Any help would be appreciated.
python-3.x
oracle
xlrd
xlwt
0 Answers
Your Answer