Code compiler error, please master pointing.

class Excel
def initialize(filename = nil)
@excel = WIN32OLE.new("excel.Application")
@excel.Visible = TRUE
if(filename == nil)
@workbook = @excel.Workbooks.Add()
else
@workbook = @excel.Workbooks.Open(filename)
end
end

def setvalue(pos,data)
@excel.Range(pos).Value = data
end

def save
@excel.Save()
end

def close
@excel.Quit()
end

def excellobj
@excel
end

end

#Test Excel
excel = Excel.new()
#Create a new file
excel = Excel.new("D:\\data\\Book1.xls")
excel.setvalue("al",33)
excel.excelobj.Range("b5").Value = "just test"
excel.save()
excel.close()

Started by Laurent at November 20, 2016 - 12:51 PM

def setvalue(pos,data)
@excel.Range(pos).Value = data
end

Among them the compiler error, that is not the definition method of Range.

The Range is a ruby class library. I do not know how to define?

Posted by Laurent at November 21, 2016 - 1:46 PM

No one? Really lonely.~~

Posted by Laurent at November 29, 2016 - 2:37 PM

The VBA method on the @excel object to a lowercase all,
Such as: (@excel.Workbooks.Add), to @excel.workbooks.add()

The method needs not the hump format (MixedCase), all lowercase.

Posted by Bonnie at December 06, 2016 - 3:34 PM

Thank you. Let me have a try.

Posted by Laurent at December 11, 2016 - 3:37 PM

$ ./ruby search.rbimport os,sysimport urllibimport urllib2C:/Users/adax/Desktop/The new text document.Txt$ vi search.rb
search_dir = "C:/Users/adax/Desktop" search_text = /import/ result = Array.new Dir.foreach(search_dir)\ { |orgFile| result.push(search_dir+'/'+orgFile) \ if (File.file?(search_dir+'/'+orgFile) \ && File.open(search_dir+'/'+orgFile).grep(search_text).length>0) if (File.file?(search_dir+'/'+orgFile) \ && File.open(search_dir+'/'+orgFile).grep(search_text).length>0) print File.open(search_dir+'/'+orgFile).grep(search_text).to_s+"\n" end } print result.join("\n")+"\n"

Posted by Laurent at December 24, 2016 - 4:30 PM

In the specified search folder file contains the specified character line
Editor: server Institute 02 Author: anonymous 2006-03-13 server network [IT168] school mainly for file and directory operation method
  #!/usr/bin/perl -w
  printf"write the path you want to search files:";
  $searchdir=<STDIN>;
  chomp $searchdir;
  printf "Input search string:";
  $searchstr=<STDIN>;
  chomp $searchstr;
  opendir(DIRHANDLE,$searchdir) || die "Cann't open $searchdir !";
  while($file=readdir DIRHANDLE) {
   if (-d "$searchdir/$file") {
   printf "$searchdir/$file is a directory! ";
   } else {
   open(FileHandle, "$searchdir/$file") || die "cann't open $searchdir/$file ! ";
   $lines=1;
   while (defined($line=<FileHandle>)) {
   $back=index($line,$searchstr);
   if ( $back != -1 ) {
   print"$file:$lines:$line";
   }
   $lines=$lines+1;
   }
   }
   close(FileHandle);
  }
  closedir(DIRHANDLE);

Posted by Laurent at January 04, 2017 - 5:24 PM