ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   convert to number format (https://www.excelbanter.com/excel-programming/310628-convert-number-format.html)

Tommy[_8_]

convert to number format
 
i'm writing code in C# that uses a string array to insert a row of
fields into an excel sheet, at the end of the excel sheet i have a cell
that is suppose to calculate the total of a column, it won't add the
total because my numbers are being inserted as text, any easy fixes??

Frank Kabel

convert to number format
 
Hi
could you post the relevant part of your code that inserts the values
in Excel

--
Regards
Frank Kabel
Frankfurt, Germany


Tommy wrote:
i'm writing code in C# that uses a string array to insert a row of
fields into an excel sheet, at the end of the excel sheet i have a
cell that is suppose to calculate the total of a column, it won't add
the total because my numbers are being inserted as text, any easy
fixes??



Tommy[_8_]

convert to number format
 
well it's actually kind of tricky, i grab a bunch of pay roll
information and create an area for each cell in a row, then i add that
row to an array of rows for the whole page and then i add it to excel,
but theres a bunch of extra formatting i do

for(int i = 0; i < pagearray.Length; i++)
{
//add 2 to the array to add values in after the headers
int irow = i + 2;
Excel.Range range = (Excel.Range)sheet.Cells.get_Range("A" +
irow.ToString().Trim(),"P" + irow.ToString().Trim());
range.Value2 = pagearray[i];

//this is the relevant part of the code

Frank Kabel wrote:

Hi
could you post the relevant part of your code that inserts the values
in Excel

--
Regards
Frank Kabel
Frankfurt, Germany


Tommy wrote:

i'm writing code in C# that uses a string array to insert a row of
fields into an excel sheet, at the end of the excel sheet i have a
cell that is suppose to calculate the total of a column, it won't add
the total because my numbers are being inserted as text, any easy
fixes??





Frank Kabel

convert to number format
 
Hi
if each element in your pagearray is a numeric value why not convert it
to a number before inserting it into Excel (don't know the C# syntax
for this).

--
Regards
Frank Kabel
Frankfurt, Germany


Tommy wrote:
well it's actually kind of tricky, i grab a bunch of pay roll
information and create an area for each cell in a row, then i add

that
row to an array of rows for the whole page and then i add it to

excel,[i]
but theres a bunch of extra formatting i do

for(int i = 0; i < pagearray.Length; i++)
{
//add 2 to the array to add values in after the headers
int irow = i + 2;
Excel.Range range = (Excel.Range)sheet.Cells.get_Range("A" +
irow.ToString().Trim(),"P" + irow.ToString().Trim());
range.Value2 = pagearray;

//this is the relevant part of the code

Frank Kabel wrote:

Hi
could you post the relevant part of your code that inserts the

values
in Excel

--
Regards
Frank Kabel
Frankfurt, Germany


Tommy wrote:

i'm writing code in C# that uses a string array to insert a row of
fields into an excel sheet, at the end of the excel sheet i have a
cell that is suppose to calculate the total of a column, it won't
add the total because my numbers are being inserted as text, any
easy fixes??



Tommy[_8_]

convert to number format
 
Good point, as simple as that solution it escaped me, thanks a lot

Frank Kabel wrote:
[i]
Hi
if each element in your pagearray is a numeric value why not convert it
to a number before inserting it into Excel (don't know the C# syntax
for this).

--
Regards
Frank Kabel
Frankfurt, Germany


Tommy wrote:

well it's actually kind of tricky, i grab a bunch of pay roll
information and create an area for each cell in a row, then i add


that

row to an array of rows for the whole page and then i add it to


excel,

but theres a bunch of extra formatting i do

for(int i = 0; i < pagearray.Length; i++)
{
//add 2 to the array to add values in after the headers
int irow = i + 2;
Excel.Range range = (Excel.Range)sheet.Cells.get_Range("A" +
irow.ToString().Trim(),"P" + irow.ToString().Trim());
range.Value2 = pagearray;

//this is the relevant part of the code

Frank Kabel wrote:


Hi
could you post the relevant part of your code that inserts the


values

in Excel

--
Regards
Frank Kabel
Frankfurt, Germany


Tommy wrote:


i'm writing code in C# that uses a string array to insert a row of
fields into an excel sheet, at the end of the excel sheet i have a
cell that is suppose to calculate the total of a column, it won't
add the total because my numbers are being inserted as text, any
easy fixes??





All times are GMT +1. The time now is 08:55 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com