473,387 Members | 1,463 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.

Writing and reading from a template Excel file using ADO.Net - results not recalculated

RJN
Hi

I've a template excel file which has all the calculations defined. There
are certain input values to be entered which gives a lot of output to
the user. I don't want to expose the excel sheet to the user as
calculations become visible. I'm writing a web interface which takes the
input values from user, updates the excel sheet and returns the
recalculated output from the excel file. I'm using ADO.Net to update and
read the excel file.

The update works fine, but when I read the output, I still get the old
values that are in the template file and not the recalculated values. It
appears that even though the input values are updated, the values are
not recalculated unless we open the excel file. Say the input in the
template is 2000 and the calculated output is 10000, now I update the
input to 4000 and the actual recalculated output is 20000, but I still
get the result as 10000.

The following is my code. I first create a copy of the template file and
work on the copy instead of the origical template.

Dim strTemplateFile As String = "E:\temp\temp.xls"
Dim strDestFileName As String = "E:\temp\temp1.xls"
File.Copy(strTemplateFile, strDestFileName)

Dim objConn As OleDb.OleDbConnection
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=""" + strDestFileName + """;Extended Properties=""Excel
8.0;HDR=No;"""
objConn = New OleDb.OleDbConnection(strConn)
objConn.Open()

Dim objCommand As New OleDbCommand
objCommand.Connection = objConn
'set the input values
objCommand.CommandText = "Update [Sheet1$E5:E5] Set F1=4000"
objCommand.ExecuteNonQuery()
objConn.Close()

Dim objAdapter As New OleDbDataAdapter("select * from [Sheet1$]",
strConn)
Dim oTable As New DataTable
objAdapter.Fill(oTable)
Response.Write(oTable.Rows(2).Item(11))

Regards

Rjn

*** Sent via Developersdex http://www.developersdex.com ***
Apr 26 '06 #1
3 3263
HI RJN,

my guess.
Perhaps when we actually work with Excel, it recomputes the formulas
based on events such as "validate" or others. It is possible that just
uploading values via OleDB does not rise such events to recompute
formulas.

Perhaps, it is needed to invoke them programmatically.

(just a guess, let me know when you find out)

-tom

RJN ha scritto:
Hi

I've a template excel file which has all the calculations defined. There
are certain input values to be entered which gives a lot of output to
the user. I don't want to expose the excel sheet to the user as
calculations become visible. I'm writing a web interface which takes the
input values from user, updates the excel sheet and returns the
recalculated output from the excel file. I'm using ADO.Net to update and
read the excel file.

The update works fine, but when I read the output, I still get the old
values that are in the template file and not the recalculated values. It
appears that even though the input values are updated, the values are
not recalculated unless we open the excel file. Say the input in the
template is 2000 and the calculated output is 10000, now I update the
input to 4000 and the actual recalculated output is 20000, but I still
get the result as 10000.

The following is my code. I first create a copy of the template file and
work on the copy instead of the origical template.

Dim strTemplateFile As String = "E:\temp\temp.xls"
Dim strDestFileName As String = "E:\temp\temp1.xls"
File.Copy(strTemplateFile, strDestFileName)

Dim objConn As OleDb.OleDbConnection
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=""" + strDestFileName + """;Extended Properties=""Excel
8.0;HDR=No;"""
objConn = New OleDb.OleDbConnection(strConn)
objConn.Open()

Dim objCommand As New OleDbCommand
objCommand.Connection = objConn
'set the input values
objCommand.CommandText = "Update [Sheet1$E5:E5] Set F1=4000"
objCommand.ExecuteNonQuery()
objConn.Close()

Dim objAdapter As New OleDbDataAdapter("select * from [Sheet1$]",
strConn)
Dim oTable As New DataTable
objAdapter.Fill(oTable)
Response.Write(oTable.Rows(2).Item(11))

Regards

Rjn

*** Sent via Developersdex http://www.developersdex.com ***


Apr 26 '06 #2
RJN
Hi Tom,

I think you're right. The calculations are not forced. But I don't want
to use excel object and force a recalculation. Microsoft doesn't
recommend using automation from ASP.Net. Is there any other way?

Thanks

rjn

*** Sent via Developersdex http://www.developersdex.com ***
Apr 27 '06 #3

I don't know. I cannot think of any way to interact at that level with
Excel via OleDb.

At this point, if I were you, I would probably forget about Excel and
code manually the computations (Excel doesn't do anything
stratospheric). Which should be a more flexible and clean solution,
anyway.

but waite also for other people opinions ...

-tom

RJN ha scritto:
Hi Tom,

I think you're right. The calculations are not forced. But I don't want
to use excel object and force a recalculation. Microsoft doesn't
recommend using automation from ASP.Net. Is there any other way?

Thanks

rjn

*** Sent via Developersdex http://www.developersdex.com ***


Apr 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Paul | last post by:
I was wondering if anyone has had an issue where using vba code to read an excel file and import the data into an access table some records are not imported from the excel file. It seems looking at...
1
by: mail2atulmehta | last post by:
Hi, I do not know if this is right place for this, but i need some help. I have a text file, whose values are seprated by a delimiter. I want to open this file in excel, ( not import it) . I have...
0
by: shintu | last post by:
Hallo, I am trying to write french accented characters é è ê in Excel worksheet using my perl script , But I am stuck here as I couldnt find a way of writing it !: My code: use strict;...
1
by: pvenu | last post by:
Hi, I know basic perl (regular expressions, pattern matching, string manipulation, reading writing into text files). Yet, my requirement is to read an input text file -> process this input file...
8
by: fahadqureshi | last post by:
Hello, I posted here before asking a question about reading excel. Now that the reading problem is solved i am having trouble on how to write to an excel file. This was my code to read the excel...
3
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have an sql database and I need to do the following, hoping there are some examples I can look at to impliment. 1. Copy an excel file on the server, just using a new name. For example...
1
by: =?Utf-8?B?ZmhpbGxpcG8=?= | last post by:
We have a code snippet that downloads data to Excel. it is writing row by row. This causes a performance issue. Any ideas on how to speed this up will be appreciated. Please find below an...
20
by: Marin Brkic | last post by:
Hello all, please, let me apologize in advance. English is not my first language (not even my second one), so excuse any errors with which I'm about to embarass myself in front of the general...
13
by: Peter | last post by:
VS2008 ans ASP.NET 3.5, Office 2003 What is the best way to run Excel Template from ASP.NET web page were the Excel is only installed on the client without any ActiveX? If so can someone point...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.