I have a model in excel and trying to feed inputs through ASP.NET to the excel and returning the back the model results over the grid in the front end. I'm using EPPlus package in ASP.NET as it doesn't need MS Office to be installed.
I have trouble getting the value of the cell where NPV [Net Present Value] and IRR [Internal rate of return] functions have been used. It always returns #VALUE or #NAME. As a workaround, I was able to calculate NPV manually but I'm having a tough time with IRR.
Is there a way in EPPlus to paste all the cells as values in the worksheet?
Or is there any other alternative?
Please help and thanks in advance
Update : I have EPPlus 4.5.3.1 and Visual studio 2013.
string strfilepath = Server.MapPath(destPath);
FileInfo fileInfo = new FileInfo(strfilepath);
ExcelPackage p = new ExcelPackage(fileInfo);
ExcelWorksheet myWorksheet = p.Workbook.Worksheets["Financial"];
GridView1.Rows[0].Cells[2].Text = float.Parse(myWorksheet1.Cells["f57"].Value.ToString()).ToString("N2");
I have tried all possible ways in EPPlus but I was not able to calculate IRR. I came up with a solution in SQL and it gives the result close to excel 's IRR function.
CREATE FUNCTION [dbo].[Ufn_irr1] (#strIDs1 VARCHAR(10),
#strIDs2 VARCHAR(10),
#guess DECIMAL(30, 10))
returns DECIMAL(30, 10)
AS
BEGIN
DECLARE #t_IDs TABLE
( a
id INT IDENTITY(0, 1),
value DECIMAL(30, 10)
)
DECLARE #strIDs VARCHAR(max)
SET #strIDs = #strIDs1 + ',' + #strIDs2
DECLARE #strID VARCHAR(12),
#sepPos INT,
#NPV DECIMAL(30, 10)
SET #strIDs = COALESCE(#strIDs + ',', '')
SET #sepPos = Charindex(',', #strIDs)
WHILE #sepPos > 0
BEGIN
SET #strID = LEFT(#strIDs, #sepPos - 1)
INSERT INTO #t_IDs
(value)
SELECT ( Cast(#strID AS DECIMAL(20, 10)) )
WHERE Isnumeric(#strID) = 1
SET #strIDs = RIGHT(#strIDs, Datalength(#strIDs) - #sepPos)
SET #sepPos = Charindex(',', #strIDs)
END
SET #guess = CASE
WHEN Isnull(#guess, 0) <= 0 THEN 0.00001
ELSE #guess
END
SELECT #NPV = Sum(value / Power(1 + #guess, id))
FROM #t_IDs
WHILE #NPV > 0
BEGIN
SET #guess = #guess + 0.00001
SELECT #NPV = Sum(value / Power(1 + #guess, id))
FROM #t_IDs
END
RETURN #guess
END
Related
I call stored procedure used:
#Entity
#Table(name = "web_id_idx")
#NamedStoredProcedureQueries({
#NamedStoredProcedureQuery(name= "check_web_id",
procedureName= "check_web_id",
parameters = {
#StoredProcedureParameter(mode = ParameterMode.IN, name = "web_id", type = String.class),
#StoredProcedureParameter(mode = ParameterMode.OUT, name = "query_web_id", type = Integer.class),
})
})
and use entity manager to call it: Object result = em.createNamedStoredProcedureQuery("check_web_id");
getQuery.setParameter("web_id", webid);
It always says: Parameter index of 2 is out of range (1, 1)
Here's the procedure that I tested on mysql, it returns either 0 or 1:
DROP PROCEDURE IF EXISTS check_web_id;
DELIMITER ;;
CREATE DEFINER=root#localhost PROCEDURE check_web_id(web_id VARCHAR(25))
begin
SET #id_var = web_id;
SET #query_check_id = CONCAT("SELECT COUNT(*) AS total FROM web_id_idx WHERE web_id = '", #id_var,"'");
PREPARE stmt FROM #query_check_id;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
end;;
DELIMITER ;
Anyone knows what is wrong?
Thanks,
Mo.
cntlMEALV_GRID_CONTROL_MMHIPO/shellcont/shell").selectColumn "XBLNR"
I'm trying to extract this into excel.
I was only able to extract row count using watch but not sure how extract this using excel
Any code or sample or help will be appreciated thanks.
Use getcellValue to cast to excel.
Set SapGuiAuto = GetObject("SAPGUI")
Set SAPApp = SapGuiAuto.GetScriptingEngine
Set SAPCon = SAPApp.Children(0)
Set session = SAPCon.Children(0)
MyGrid = "cntlMEALV_GRID_CONTROL_MMHIPO/shellcont/shell"
iRows = session.findById(MyGrid).RowCount()
'Fill excel sheet
Do While i < iRows
Cells(i + 1, 1).Value = session.findById(MyGrid).getcellValue(i, "XBLNR")
i = i + 1
Loop
I want to insert a Dataframe in a table using ODBC.jl , the table already exists and it seems that i can't use the function ODBC.load with it (even with the append=true).
usually i insert DataFrames with copyIn by loading the dataframe as a csv but with just ODBC it seems i can't do that .
The last thing i found is :
stmt = ODBC.prepare(dsn, "INSERT INTO cool_table VALUES(?, ?, ?)")
for row = 1:size(df, 1)
ODBC.execute!(stmt, [df[row, x] for x = 1:size(df, 2)])
end
but this is line by line , it's incredibly long to insert everything .
I tried also to do it myself like this :
_prepare_field(x::Any) = x
_prepare_field(x::Missing) = ""
_prepare_field(x::AbstractString) = string(''', x, ''')
row_names = join(string.(Tables.columnnames(table)), ",")
row_strings = imap(Tables.eachrow(table)) do row
join((_prepare_field(x) for x in row), ",") * "\n"
end
query = "INSERT INTO $tableName($row_names) VALUES $row_strings"
#debug "Inserting $(nrow(df)) in $tableName)"
DBInterface.execute(db.conn, query)
but it throw me an error because of some "," not at the right place at like col 9232123
which i can't find because i have too many lines , i guess it's the _prepare_field that doesn't cover all possible strings escape but i can't find another way .
Did i miss something and there is a easier way to do it ?
Thank you
Im trying to retrieve the latest versions of audit questions stored in table T3 of the hs_audit.sqlite. I have tried multiple versions of the cur.exectute line but keep getting a result = None. I'm new to sqlite so can anyone help me with the correct syntax.
If I execute the cur.execute line as follows
cur.execute("SELECT hvq1 FROM T3 WHERE audit_ver = 1")
and remove
con.text_factory = str
it works so i think the problem must be the use of variables in the sqlite command.
max_audit_ver = 1
audit_questions = ["hvq1", "hvq2", "hvq3", "hvq4", "hvq5"]
count = 0
for quest in audit_questions:
con = sqlite3.connect("hs_audit.sqlite")
con.text_factory = str
cur = con.cursor()
cur.execute("SELECT '%s' FROM T3 WHERE audit_ver = '%s'" % (quest, max_audit_version))
result = cur.fetchone()
con.close()
print "Question =%s" % (quest)
print "Audit Version =%s" % (max_audit_version)
print "The Count Is =%s" % (count)
print "The return from the DB is =%s" % (result)
count += 1
Mind the synthax... max_audit_version and max_audit_ver
On the other hand, you should read this page, you will find some important note such as :
# Never do this -- insecure!
symbol = 'RHAT'
c.execute("SELECT * FROM stocks WHERE symbol = '%s'" % symbol)
# Do this instead
t = ('RHAT',)
c.execute('SELECT * FROM stocks WHERE symbol=?', t)
print c.fetchone()
# Larger example that inserts many records at a time
purchases = [('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
('2006-04-06', 'SELL', 'IBM', 500, 53.00),
]
c.executemany('INSERT INTO stocks VALUES (?,?,?,?,?)', purchases)
There's the simplified version of my code who keep raise me ORA-06502:
declare
p_filter varchar2(300) := '2012';
p_value varchar2(300) := '12345.000';
w_new_value number(13,3) := null ;
w_count number(4) := null ;
BEGIN
SELECT count(*)
INTO w_count
FROM dual
where p_filter = p_filter;
--- more filters
if w_count != 0 then
w_new_value := p_value / w_count;
else
w_new_value := p_value;
end if;
-- do something
end;
/
Someone can give me a help?
DataBase Details
nls_language = italian
nls_territory = italy
nls_currency = �
nls_iso_currency = italy
nls_numeric_characters = ,.
nls_calendar = gregorian
nls_date_format = dd-mon-rr
nls_date_language = italian
nls_characterset = we8iso8859p15
nls_sort = west_european
nls_time_format = hh24:mi:ssxff
nls_timestamp_format = dd-mon-rr hh24:mi:ssxff
nls_time_tz_format = hh24:mi:ssxff tzr
nls_timestamp_tz_format = dd-mon-rr hh24:mi:ssxff tzr
nls_dual_currency = �
nls_nchar_characterset = al16utf16
nls_comp = binary
nls_length_semantics = byte
nls_nchar_conv_excp = false
First, this is always going return a value of 1.
SELECT count(*)
INTO w_count
FROM dual
It doesn't matter what the qualifier is.
Lastly, I just ran your simplified code example in Oracle 11R2 and it didn't throw an exception.
I added the following statement in place of your "do something" comment:
dbms_output.put_line('w_new_value: ' || w_new_value || '. w_count: ' || w_count);
The result was:
w_new_value: 12345. w_count: 1
So, I think you've simplified your example into oblivion. You need to provide something that actually shows the error.
Good luck.
I found myself the ansewer and i think is useful for other know.
The real problem of the script for my DB is the language.
The italian "version" of Oracle accept , instead of the . for translate the VARCHAR2 into NUMBER unlike the most of other country.
For make the code running well the solution is
w_new_value := replace(p_value,'.',',') / w_count;
This trick finally allows the DB use my VARCHAR2 param like a NUMBER