473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Insert the records in excel sheet

198 100+
can any one help by providing the method inserting the records in excel file
because i created it all it works fine but i have no idea about how to insert new records in the existing excel file.
e.g
my excel sheet has filled first 20 rows and then
i want to insert the new records in the excel sheet starts from 21st row
is any idea about this, please send me
thanks
Nov 24 '07 #1
14 2477
daniel aristidou
491 256MB
can any one help by providing the method inserting the records in excel file
because i created it all it works fine but i have no idea about how to insert new records in the existing excel file.
How are you inserting the data into the excel sheet and which version of excel are you using? Also where is the data being taken from?
Nov 24 '07 #2
kadghar
1,295 Expert 1GB
can any one help by providing the method inserting the records in excel file
because i created it all it works fine but i have no idea about how to insert new records in the existing excel file.
e.g
my excel sheet has filled first 20 rows and then
i want to insert the new records in the excel sheet starts from 21st row
is any idea about this, please send me
thanks
hi, i think that you'll have to open the excel file and insert the rows you want..
it aint that hard:

Expand|Select|Wrap|Line Numbers
  1. dim obj1 as object
  2. set obj1 = createobject("excel.application")
  3. obj1.workbooks.open "c:\myfile.xls"
  4. obj1.cells(21,1).value = "This is row 21"
after you do this, i recommend you to make visible the obj1 and then close it. sometimes when you close it while not visible it generates some trash. and of course, save it so it'll keep the changes... use obj1.visible = true, obj1.activeworkbook.saveas, etc.. commands are quite intuitive

HTH
Nov 24 '07 #3
veer
198 100+
hello expert
i am inserting the data from sql server and my excel version is 97
i tell you what is about my programe
i have five field in my excel sheet and i want to insert the data in excel sheet daily through programing, firstly i open the file and insert data and then save it next time i also want to insert the data into the same sheet continue from the previous end row . If i manually change the row and column name then it works fine but i have no idea how i insert the data so that it automatically choose the last empty row and insert data please send me some coding
My programing is

Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object

Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Open("C:\varinder.xls")
oExcel.UserControl = True
Set oSheet = oBook.Worksheets(1)
oSheet.Range("A1").Value = "Last Name"
oSheet.Range("B1").Value = "First Name"
oSheet.Range("A1:B1").Font.Bold = True
oSheet.Range("A5").Value = "delhi"
oSheet.Range("B5").Value = "jammu"
Save the Workbook and Quit Excel
oBook.SaveAs "C:\varinder.xls"
oExcel.Quit
thanks


How are you inserting the data into the excel sheet and which version of excel are you using? Also where is the data being taken from?
Nov 26 '07 #4
veer
198 100+
hello expert
you send me the code which i have to do manually but i want a general formula so that every time when i execute the programe it automatically search the sheet find the empty row and insert the data

thanks


hi, i think that you'll have to open the excel file and insert the rows you want..
it aint that hard:

Expand|Select|Wrap|Line Numbers
  1. dim obj1 as object
  2. set obj1 = createobject("excel.application")
  3. obj1.workbooks.open "c:\myfile.xls"
  4. obj1.cells(21,1).value = "This is row 21"
after you do this, i recommend you to make visible the obj1 and then close it. sometimes when you close it while not visible it generates some trash. and of course, save it so it'll keep the changes... use obj1.visible = true, obj1.activeworkbook.saveas, etc.. commands are quite intuitive

HTH
Nov 26 '07 #5
kadghar
1,295 Expert 1GB
hello expert
you send me the code which i have to do manually but i want a general formula so that every time when i execute the programe it automatically search the sheet find the empty row and insert the data

thanks
i'd use a DO or a WHILE to search it, once you've created the Excel Application, instead of insert the data in the cell A21, you can do it this way:

Expand|Select|Wrap|Line Numbers
  1. dim i as long
  2. i=1
  3. while obj1.cells(i,1).value <> ""
  4.     i=i+1
  5. wend
  6. obj1.cells(i,1).value = "This is the first empty cell"
HTH
Nov 26 '07 #6
veer
198 100+
thanks very much expert it is working , if i need any help recording this project i will connect you latter
varinder


i'd use a DO or a WHILE to search it, once you've created the Excel Application, instead of insert the data in the cell A21, you can do it this way:

Expand|Select|Wrap|Line Numbers
  1. dim i as long
  2. i=1
  3. while obj1.cells(i,1).value <> ""
  4.     i=i+1
  5. wend
  6. obj1.cells(i,1).value = "This is the first empty cell"
HTH
Nov 26 '07 #7
veer
198 100+
hello expert
is there any method to repeate one column value again and again in vb with orher columns value changes during every execution
e.g
i have some operator code which i want to repeate and then compare these codes with the codes that i am accessing from sql table.
thanks



i'd use a DO or a WHILE to search it, once you've created the Excel Application, instead of insert the data in the cell A21, you can do it this way:

Expand|Select|Wrap|Line Numbers
  1. dim i as long
  2. i=1
  3. while obj1.cells(i,1).value <> ""
  4.     i=i+1
  5. wend
  6. obj1.cells(i,1).value = "This is the first empty cell"
HTH
Nov 26 '07 #8
kadghar
1,295 Expert 1GB
hello expert
is there any method to repeate one column value again and again in vb with orher columns value changes during every execution
e.g
i have some operator code which i want to repeate and then compare these codes with the codes that i am accessing from sql table.
thanks
yeap, when i use CELLS( I, J ) I is for rows, J is for columns. you can save some value into a string or a double and then use it as you want. for example if you want to compare cell A1 with each cell in B1:B5, and show if they're the same in C1:C5 just:

Expand|Select|Wrap|Line Numbers
  1. dim a as string
  2. dim i as integer
  3. with obj1
  4.     a = .cells(1,1).value
  5.     for i = 1 to 5
  6.         if .cells(i,2).value = a then .cells(i,3) = "YES"
  7.     next
  8. end with
HTH
Nov 26 '07 #9
veer
198 100+
hello expert
i used your code but i want the different result
e,g In string " a" i have the value 702 and i want to search this value in the whole Ist column and if matched the corresponding record i,e 12 must be shown in the next column of same row

please provide some method
thanks



yeap, when i use CELLS( I, J ) I is for rows, J is for columns. you can save some value into a string or a double and then use it as you want. for example if you want to compare cell A1 with each cell in B1:B5, and show if they're the same in C1:C5 just:

Expand|Select|Wrap|Line Numbers
  1. dim a as string
  2. dim i as integer
  3. with obj1
  4.     a = .cells(1,1).value
  5.     for i = 1 to 5
  6.         if .cells(i,2).value = a then .cells(i,3) = "YES"
  7.     next
  8. end with
HTH
Dec 12 '07 #10
kadghar
1,295 Expert 1GB
hello expert
i used your code but i want the different result
e,g In string " a" i have the value 702 and i want to search this value in the whole Ist column and if matched the corresponding record i,e 12 must be shown in the next column of same row

please provide some method
thanks
Well, i dont thik providing methods will be the best way, why dont you give it a try, that you're asking can be solved by slightly changing the code before, just change the range of the FOR, you might use END FOR, or even replace it with a DO.

Good luck there.
Dec 12 '07 #11
veer
198 100+
hello expert
i changed the range of for loop and it works
thanks




Well, i dont thik providing methods will be the best way, why dont you give it a try, that you're asking can be solved by slightly changing the code before, just change the range of the FOR, you might use END FOR, or even replace it with a DO.

Good luck there.
Dec 13 '07 #12
poolboi
170 100+
hm...sorrie both guys

hm..i came across this threadd and found it similar to my problem
but i'm using perl now and my data outputs to an excel file
the module i'm using is win32::OLE
if i use the same algorithms will it work?
cos i have no idea how i can open this file in perl..pls advise below is my code for ya to see thanks~

Expand|Select|Wrap|Line Numbers
  1.  
  2.     use Win32::OLE;
  3.  
  4.         # use existing instance if Excel is already running
  5.         eval {$ex = Win32::OLE->GetActiveObject('Excel.Application')};
  6.         die "Excel not installed" if $@;
  7.         unless (defined $ex) {
  8.             $ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;})
  9.                     or die "Oops, cannot start Excel";
  10.         }
  11.  
  12.  
  13.         # get a new workbook
  14.         $book = $ex->Workbooks->Add;
  15.     $sheet = $book->Worksheets(1);
  16.  
  17.         # write a 2 rows by 3 columns range
  18.     $y = 2;
  19.     $x = 1;
  20.         $sheet->Range("A$x:J$y")->{Value} = [['Date','Total (IN)','Succ (IN)','Pk (IN)/Hrs','Pk (OUT)/Hrs','Peak Hour','Total (OUT)','Succ (OUT)','MO(IN)','MO(OUT)'],
  21.                                            [$date, $total_in, $succ_in,$pk_in,$pk_out,"$pk_hour - $pk_hour_dur hr",$total_out,$succ_out ]];
  22.  
  23.  
  24.     $sheet->Range("K1:L2")->{Value} = [['Pk Msg/sec','Max Pk Msg/sec'],
  25.                       [$max_pk_msg,$pk_msg]];
  26.  
  27.  
  28.     foreach(@parameters)
  29.     {
  30.     $sheet->Cells(2,9)->{Value} = [$parameter_in_array{$_}];
  31.     $sheet->Cells(2,10)->{Value} = [$parameter_out_array{$_}];
  32.     }
  33.  
  34.  
  35.  
  36.          # print "XyzzyPerl"
  37.         $array = $sheet->Range("A1:I1")->{Value};
  38.         for (@$array) {
  39.             for (@$_) {
  40.                 print defined($_) ? "$_|" : "<undef>|";
  41.             }
  42.             print "\n";
  43.         }
  44.  
  45.         # save and exit
  46.  
  47.         $book->SaveAs ("C:\\Documents and Settings\\clong\\Desktop\\perl\\$save_file_name.xls") ;
  48.         undef $book;
  49.         undef $ex;
  50.  
Jan 29 '08 #13
kadghar
1,295 Expert 1GB
hm...sorrie both guys

hm..i came across this threadd and found it similar to my problem
but i'm using perl now and my data outputs to an excel file
the module i'm using is win32::OLE
if i use the same algorithms will it work?
cos i have no idea how i can open this file in perl..pls advise below is my code for ya to see thanks~
I've no idea =(
I havent worked very much with perl, but why dont you post your question in the perl forum? Im sure they can provide a good answer.
Jan 29 '08 #14
poolboi
170 100+
hm...i've already posted it
but not very good response
basically i'm trying to like:
step 1: have a if ... else statement to determine if an excel file $file exist, and if
it doesn't we create a new file $file
step 2: if the file exist then i have to append $file like wat u did in this thread

hm...i'm alreadying doing part 1...but part 2 is abit tough
thanks anyway dude
Jan 29 '08 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
3
by: TM | last post by:
Is there any way that I can take the records from a datagrid and paste them into an Excel sheet, then print preview or print the sheet ? Is there any way I can sort the sheet before I print it ?...
0
by: Mamatha | last post by:
Hi When i clicked a button, i want to insert data from listview in VB.NET to Excel sheet. If you know the solution either above or below is ok for me. I know how to insert from a textfile,but...
1
by: kannabiran | last post by:
Hi everyone, Im using the C# asp.net as the front end and i need to use the Excel sheet as the back end.i want to select the records which is available in the excel sheet using query and...
0
by: imtmub | last post by:
Hi All, when i am trying to insert records from excel sheet to wko table in my database. My Excel sheet contains 400 records. I am getting the error message. please check this code and advise me. ...
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
1
kirubagari
by: kirubagari | last post by:
Hai experts, How to duplicate the data from 1 excel sheet to another excel sheet 2. Lets say Name Voucher Value Voucher Number lee 300.00 ...
1
by: PeacefulSoul | last post by:
Hello, I have a lot of excel sheets which columns are slightly different, i want to import all of these sheets (one at a time) into ONE SQL TABLE. I'll give an example : Say ive written the...
0
by: nam pai | last post by:
im using java excel api and trying to add some more records to the existing excel sheet. im using writable workbook hence every time i try to add a record it creates a new workbook and writes the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.