Initial commit: skills library
- 70 skills with code and documentation - Add .gitignore (ignore __pycache__, output/, temp/, venv/) - Clean up test intermediates and caches
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import pandas as pd
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
def convert_xls_to_xlsx(xls_file, xlsx_file=None):
|
||||
"""将.xls文件转换为.xlsx文件"""
|
||||
if not xlsx_file:
|
||||
xlsx_file = os.path.splitext(xls_file)[0] + ".xlsx"
|
||||
|
||||
try:
|
||||
# 尝试使用xlrd读取.xls文件
|
||||
df = pd.read_excel(xls_file, engine="xlrd")
|
||||
|
||||
# 保存为.xlsx格式
|
||||
df.to_excel(xlsx_file, index=False)
|
||||
|
||||
print(f"成功转换: {xls_file} -> {xlsx_file}")
|
||||
print(f"数据形状: {df.shape}")
|
||||
print("前几行预览:")
|
||||
print(df.head())
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"转换失败: {e}")
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2:
|
||||
print("用法: python convert_xls_to_xlsx.py <input.xls> [output.xlsx]")
|
||||
sys.exit(1)
|
||||
|
||||
input_file = sys.argv[1]
|
||||
output_file = sys.argv[2] if len(sys.argv) > 2 else None
|
||||
|
||||
convert_xls_to_xlsx(input_file, output_file)
|
||||
Reference in New Issue
Block a user