Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 64dccea

Browse files
自用script
1 parent 49ffddb commit 64dccea

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

excelToSql.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) 2021. 楊鵬. All Rights Reserved.
2+
3+
import pandas as pd
4+
5+
if __name__ == '__main__':
6+
filepath = './r3ippan3.xlsx'
7+
result = []
8+
with pd.ExcelFile(filepath) as xlsx:
9+
for sheetname in xlsx.sheet_names:
10+
df = pd.read_excel(xlsx, sheetname, index_col=None, header=None)
11+
row = (
12+
' DB::insert("INSERT INTO insurance_rates(started_at, ended_at, prefecture_id',
13+
'health_insurance_rate1, health_insurance_rate2, employee_pension_rate) VALUES(\'2021/04/01\'',
14+
'\'2022/03/31\'',
15+
str(xlsx.sheet_names.index(sheetname) + 1),
16+
str(round(df.iloc[8, 5], 4)),
17+
str(round(df.iloc[8, 7], 4)),
18+
str(round(df.iloc[8, 9], 4)) + ');"); // ' + df.iloc[5, 0][1: -1] + '\n',
19+
)
20+
result.append(', '.join(row))
21+
output_file = 'sql.txt'
22+
with open(output_file, 'w', encoding='utf-8') as f:
23+
f.writelines(result)

0 commit comments

Comments
 (0)