excel - Copy a large amount of data of a specific format/pattern from one Excel file to another Excel file with different data pattern?
问题描述
I want to Copy some data (of a specific pattern) from one Excel file and then Paste that data to another Excel file but in a different pattern. I also want to skip a certain number of rows from source file on a specific pattern ( copy data from 5 rows then skip next 5 rows , then copy data from next 5 rows and skip next 5 rows and so on). My Source file contains about 80,000 rows so copying manually using simple copy and paste using mouse clicks is very slow procedure and time consuming. Please tell me that what is the VBA Macro code for this specific problem that copy all that data automatically fulfilling the criteria. Thanks!
This is the Image of both files explaining the criteria of copy/paste: https://drive.google.com/open?id=1wVjIfPSFkoSPw08rzVPdzqluKGynNKKT
解决方案
我已经解决了这个问题。感谢大家免费提供负面反馈。如果你不能发表好的评论,那么至少不要发表不好的评论。批评某人是最简单的任务。
顺便说一句,如果有人遇到此类问题,那么这是我用 Python 编写的简单解决方案代码:
import csv
#loading Source CSV file and parse it into list of integer numbers
with open('Source.csv', 'r') as csvfile:
scr_data_list = []
for row in csv.reader(csvfile, delimiter=','):
scr_data_list.append(row[0]) # careful here with [0]
csvfile.close()
#print scr_data_list
#print "\n"
temp_scr_list = [] # temp list to store 5 values from Source list
temp_des_list = [] # temp list to store 9 numbers drived from "temp_scr_list"
des_data_list = [] # Destination List contaning whole data
step = 5
i = 0
while i < len(scr_data_list):
j = 0
while j <5:
temp_scr_list.append(float(scr_data_list[i+j]))
j = j+1
# Main logic of this program
#print temp_scr_list
temp_des_list.append(temp_scr_list[2]) # value at -20 offset
temp_des_list.append(temp_scr_list[2]+0.05) # value at -14 offset (derived)
temp_des_list.append(temp_scr_list[1]-0.2) # value at -10 offset (derived)
temp_des_list.append(temp_scr_list[1]) # value at -5 offset
temp_des_list.append(temp_scr_list[0]) # value at 0 offset
temp_des_list.append(temp_scr_list[3]) # value at 5 offset
temp_des_list.append(temp_scr_list[3]-0.2) # value at 10 offset (derived)
temp_des_list.append(temp_scr_list[4]+0.05) # value at 14 offset (derived)
temp_des_list.append(temp_scr_list[4]) # value at 20 offset
des_data_list.extend(temp_des_list)
# step 5 values forward
i=i+5
# clear the lists
temp_scr_list = []
temp_des_list = []
print len(des_data_list)
# write the numbers from "des_data_list" list to a CSV file
with open('Destination.csv', 'wb') as writeFile:
for r in des_data_list:
writeFile.write(str(r) + "\n")
writeFile.close()
推荐阅读
- c# - 日期之间所有帐户的 MS Dynamics 审计历史记录
- google-chrome - Instagram 个人资料的搜索引擎缓存
- zsh - zsh 的标准文件夹结构是什么?
- typescript - 通过模块扩充向外部类添加方法:错误
- r - R Shiny:使用逻辑条件从 checkboxGroupInput() 反应性地子集数据帧
- html - 单品变化包裹填充物,额外空间 woocomerce
- confusion-matrix - 对验证数据使用 SMOTE(即不平衡)
- kubernetes - 如何在 kubernetes pod 上挂载 afs 文件系统
- javascript - 从数组中获取唯一值,但也显示它的重复数量(javascript - reactjs)
- django - 尝试从 django 应用程序创建可执行文件时出现 Pyinstaller 问题