首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

急加急怎么用perl将txt文件写到Excel里面

2013-01-02 
急急急,加急!如何用perl将txt文件写到Excel里面现在有1000多个txt数据文件,我想把他们写到Excel文件里,我

急急急,加急!如何用perl将txt文件写到Excel里面
现在有1000多个txt数据文件,我想把他们写到Excel文件里,我记得perl可以做到,有谁知道怎么做吗?涉及到那些模块,在哪里可以学到,麻烦各位大神了!
[解决办法]
中文 Excel 读写终级解决方案
http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=1626493&extra=page%3D1%26filter%3Ddigest%26digest%3D1%26digest%3D1
[解决办法]

#========================================================
#              2012/07/31 23:18:22   
#              查找        
#========================================================
from win32com.client import Dispatch
import time
api = Dispatch('Excel.Application')
work_book = api.Workbooks.Open(r'C:\Users\ago\Desktop\test.xls')
try:
    work_sheet = work_book.Worksheets
    '''
    #创建单元格内容
    for i in range(1,27):
        for j in range(1,27):
            ch = 65 + j -1
            ch = chr(ch) + str(i)
            work_sheet(1).Cells(i,j).Value = ch
work_book.Save()
    '''
    m_range = work_sheet(1).Range('A1:Z26').Find('B15')#查找单元格内容为'B15'的range
    for i in m_range:
        print i #输出单元格内容为'B15'的Cell
    
    work_book.Close()
except Exception,e:
    print e
    work_book.Save()
    work_book.Close()

[解决办法]
#========================================================
#        注:在运行之前先得创建D:/screenshot.bmp以及D:/1.xls                                        
#              2012/07/29 19:37:50                  
#========================================================
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from win32com.client import Dispatch
import win32com.client
class easyExcel:
      """A utility to make it easier to get at Excel.    Remembering
      to save the data is your problem, as is    error handling.
      Operates on one workbook at a time."""
      def __init__(self, filename=None):
          self.xlApp = win32com.client.Dispatch('Excel.Application')
          if filename:


              self.filename = filename
              self.xlBook = self.xlApp.Workbooks.Open(filename)
          else:
              self.xlBook = self.xlApp.Workbooks.Add()
              self.filename = ''  
    
      def save(self, newfilename=None):
          if newfilename:
              self.filename = newfilename
              self.xlBook.SaveAs(newfilename)
          else:
              self.xlBook.Save()    
      def close(self):
          self.xlBook.Close(SaveChanges=0)
          del self.xlApp
      def getCell(self, sheet, row, col):
          "Get value of one cell"
          sht = self.xlBook.Worksheets(sheet)
          return sht.Cells(row, col).Value
      def setCell(self, sheet, row, col, value):
          "set value of one cell"
          sht = self.xlBook.Worksheets(sheet)
          sht.Cells(row, col).Value = value
      def getRange(self, sheet, row1, col1, row2, col2):
          "return a 2d array (i.e. tuple of tuples)"
          sht = self.xlBook.Worksheets(sheet)
          return sht.Range(sht.Cells(row1, col1), sht.Cells(row2, col2)).Value
      def addPicture(self, sheet, pictureName, Left, Top, Width, Height):
          "Insert a picture in sheet"
          sht = self.xlBook.Worksheets(sheet)
          sht.Shapes.AddPicture(pictureName, 1, 1, Left, Top, Width, Height)
  
      def cpSheet(self, before):
          "copy sheet"
          shts = self.xlBook.Worksheets
          shts(1).Copy(None,shts(1))

if __name__ == "__main__":
      PNFILE = r'D:/screenshot.bmp'
      xls = easyExcel(r'D:/1.xls')
      xls.addPicture('Sheet1', PNFILE, 20,20,1000,1000)


      xls.cpSheet('Sheet1')
      xls.save()
      xls.close()
  


[解决办法]
#========================================================
#              2012/07/31 23:18:22                  
#========================================================
from win32com.client import Dispatch
import time
api = Dispatch('Excel.Application')
work_book = api.Workbooks.Open(r'C:\Users\ago\Desktop\test.xls')
try:
    work_sheet = work_book.Worksheets
    '''
    #创建单元格内容
    for i in range(1,27):
        for j in range(1,27):
            ch = 65 + j -1
            ch = chr(ch) + str(i)
            work_sheet(1).Cells(i,j).Value = ch
work_book.Save()
    '''
    m_range = work_sheet(1).Range('A1:Z26').Find('B15')#查找单元格内容为'B15'的range
    for i in m_range:
        print i #输出单元格内容为'B15'的Cell
    
    work_book.Close()
except Exception,e:
    print e
    work_book.Save()
    work_book.Close()

热点排行