我在將文件寫入從Excel取得文件名的特定路徑中遇到了一些麻煩。下面是我使用過程中的運行時間將文件寫入特定路徑的紅寶石從excel中取出文件名稱
out_file = File.new (@temp_path/ "#{obj_info[3].to_s}","w")
"#{obj_info[3].to_s}" = sample.txt
值sample.txt
來自Excel中的代碼
@temp_path = "C:/Users/Somefolder/"
顯示的錯誤是:
NoMethodError: undefined method `[]' for nil:NilClass
然而,如果代碼是:
out_file = File.new ("#{obj_info[3].to_s}","w")
它在默認目錄中成功創建了一個名爲sample.txt的文件。但是,我希望將其存儲在特定的目錄中,並且需要從Excel傳遞文件名。 任何幫助,非常感謝。
在/和「?@ temp_path /」#{obj_info [3] .to_s} –