Project

General

Profile

Actions

Bug #12404

closed

Segmentation fault in ruby 2.3.0p0

Added by fitmap (Justin Peal) over 8 years ago. Updated over 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.0p0 (2015-12-25 revision 53290) [x64-mingw32]
[ruby-core:75632]

Description

Content of genexcel.rb (Can run in Ruby 2.2 x64)

#!/usr/bin/env ruby
# encoding: utf-8

require 'win32ole'

class Member
  def full_path xls_name
    File.expand_path(xls_name.encode('gb18030')).encode('utf-8').gsub('/', "\\")
  end

  def book excel, txt_name, xls_name
    workbook = excel.Workbooks.Add
    begin
      worksheet = workbook.worksheets(1)
      worksheet.Name = '成员表'
      worksheet.Rows.RowHeight = 20
      worksheet.Range("A2").select
      begin
        excel.ActiveWindow.FreezePanes = true
      rescue
      end
      worksheet.Cells.Font.Size = 9
      widths = [3, 3, 3, 5.63, 7.00, 3.75, 9, 3.75, 3.75, 5.63, 3.75, 3.75, 3.75, 3.75]
      titles = %w{组 号 CXO 上车点 昵称 性别 手机号码 区 街道 社区 总数 本线 对讲 奖金}
      worksheet.Range("G:G").NumberFormat = '@'
      ('A'..'N').each_with_index do |column, index|
        worksheet.Range("#{column}1").ColumnWidth = widths[index]
        worksheet.Range("#{column}1").Value = titles[index]
      end
      line = 1
      File.open(txt_name, 'r:gb18030') do |fil|
       fil.each_line do |row|
          line += 1
          columns = row.chomp.split("\t")
          ('A'..'N').each_with_index do |column, index|
            worksheet.Range("#{column}#{line}").Value = columns[index]
          end
       end
      end
      worksheet.Range("A1:N#{line}").HorizontalAlignment = 1
      worksheet.Range("A1:N#{line}").VerticalAlignment = 2     # (1~5)
      worksheet.Range("A1:N#{line}").Borders.Weight = 2
      worksheet.Range("A1:N#{line}").Borders.ColorIndex = 1
      worksheet.Range("A1:N#{line}").Borders.LineStyle = 1     # (1~13)
      worksheet.Range("A1:N1").Interior.ColorIndex = 39
      worksheet.Range("A2:N#{line}").Interior.ColorIndex = 2
      workbook.saveas(full_path(xls_name))
    ensure
      workbook.close
    end
  end

  def main txt_name, xls_name
    WIN32OLE.codepage = WIN32OLE::CP_UTF8
    excel = WIN32OLE::new('ket.Application')   # http://bbs.wps.cn/thread-22427901-1-1.html
    begin
      # excel.AskToUpdateLinks WPS不认识
      excel.Visible = excel.DisplayAlerts = excel.ScreenUpdating = false
      excel.SheetsInNewWorkbook = 1
      File.delete(xls_name) if File.exist?(xls_name)
      book excel, txt_name, xls_name
    ensure
      excel.Quit
    end
  end
end

if $0 == __FILE__
  Dir.chdir 'C:/K/Hike'
  Member.new.main('simple.txt', 'simple.xls')
end

Files

genexcel.rb (2.31 KB) genexcel.rb fitmap (Justin Peal), 05/20/2016 02:54 AM
bug-12404.log (27.9 KB) bug-12404.log nobu (Nobuyoshi Nakada), 05/20/2016 05:52 AM

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • File bug-12404.log bug-12404.log added
  • Description updated (diff)
  • Status changed from Open to Feedback
  • Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.1: DONTNEED, 2.2: DONTNEED, 2.3: UNKNOWN

Maybe related to [Bug #11880]?
Try 2.3.1.

Actions #2

Updated by jeremyevans0 (Jeremy Evans) over 5 years ago

  • Status changed from Feedback to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0