array question

  • Thread starter Thread starter NuB
  • Start date Start date
N

NuB

I'm passing in an array and I need to write them to a text file. I'm getting
the data in fine but instead of writing it all to one file it generates a
seperate file for each item. How can I put each item onto the same file.


comes in like
BMW Lexus Chevy Saab

and its generating a file for
BMW Lexux Chevy Sabb

I need all of these on the same file
 
NuB,

Can you show the code you are using? It would seem you probably are
initializing your file stream (or file writer) in a loop, and creating a new
one through each iteration?

Hope this helps.
 
I've tried this and its not working 100%
it either gives me the last record or just generates a file for each one.
now i'm generating an excel sheet on the fly. I have it working in one app,
but that it reading a file directly, now I need to pass in the information
and its causing me some pain. Its either giving me the last record passed
in, or generating an file for each record.


for (int i = 1; i <= carMake.length; i++)
{
newSheet.get_range("A" + x.ToString(),missing).Value2 = carMake;
x+=1;
}

Nicholas Paldino said:
NuB,

Can you show the code you are using? It would seem you probably are
initializing your file stream (or file writer) in a loop, and creating a
new one through each iteration?

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

NuB said:
I'm passing in an array and I need to write them to a text file. I'm
getting the data in fine but instead of writing it all to one file it
generates a seperate file for each item. How can I put each item onto the
same file.


comes in like
BMW Lexus Chevy Saab

and its generating a file for
BMW Lexux Chevy Sabb

I need all of these on the same file
 
NuB,

You still aren't showing the code that you are using to generate a file.
What you are showing is just something that increments the value in ranges.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

NuB said:
I've tried this and its not working 100%
it either gives me the last record or just generates a file for each one.
now i'm generating an excel sheet on the fly. I have it working in one
app, but that it reading a file directly, now I need to pass in the
information and its causing me some pain. Its either giving me the last
record passed in, or generating an file for each record.


for (int i = 1; i <= carMake.length; i++)
{
newSheet.get_range("A" + x.ToString(),missing).Value2 = carMake;
x+=1;
}

Nicholas Paldino said:
NuB,

Can you show the code you are using? It would seem you probably are
initializing your file stream (or file writer) in a loop, and creating a
new one through each iteration?

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

NuB said:
I'm passing in an array and I need to write them to a text file. I'm
getting the data in fine but instead of writing it all to one file it
generates a seperate file for each item. How can I put each item onto
the same file.


comes in like
BMW Lexus Chevy Saab

and its generating a file for
BMW Lexux Chevy Sabb

I need all of these on the same file
 
how about this: this is generating the new file
// instance of excel
Excel.Application newExcel= new Excel.Application();
Excel.Workbook newWorkBook=
excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Excel._Worksheet carSales = (Excel._Worksheet)
excelBook.Worksheets.get_Item(1);

try
{

//allow the user to see it the spreadsheet once genertated
excelApp.Visible = true;
carSales.Columns.ColumnWidth = 21.71;
//create headers in the columns
carSales.get_Range("A1",missing).Value2 = "Car Make";
carSales.get_Range("A1",missing).Font.Bold = true;
carSales.get_Range("B1",missing).Value2 = "VIN Number";

//get each record being passed in
start on the 3rd row of the spreadsheet
x = 3;
for (int i = 1; i <= carMake.length; i++)
{
carSales.get_range("A" + x.ToString(),missing).Value2 =
carMake;
//go to next row if applicable
x+=1;
}
}
catch (Excpetion ex)
{

}






Nicholas Paldino said:
NuB,

You still aren't showing the code that you are using to generate a
file. What you are showing is just something that increments the value in
ranges.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

NuB said:
I've tried this and its not working 100%
it either gives me the last record or just generates a file for each one.
now i'm generating an excel sheet on the fly. I have it working in one
app, but that it reading a file directly, now I need to pass in the
information and its causing me some pain. Its either giving me the last
record passed in, or generating an file for each record.


for (int i = 1; i <= carMake.length; i++)
{
newSheet.get_range("A" + x.ToString(),missing).Value2 = carMake;
x+=1;
}

Nicholas Paldino said:
NuB,

Can you show the code you are using? It would seem you probably are
initializing your file stream (or file writer) in a loop, and creating a
new one through each iteration?

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

"NuB" <CSharpCoder> wrote in message
I'm passing in an array and I need to write them to a text file. I'm
getting the data in fine but instead of writing it all to one file it
generates a seperate file for each item. How can I put each item onto
the same file.


comes in like
BMW Lexus Chevy Saab

and its generating a file for
BMW Lexux Chevy Sabb

I need all of these on the same file
 
NuB,

This can't be doing it, as there is no call to save the file.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

NuB said:
how about this: this is generating the new file
// instance of excel
Excel.Application newExcel= new Excel.Application();
Excel.Workbook newWorkBook=
excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Excel._Worksheet carSales = (Excel._Worksheet)
excelBook.Worksheets.get_Item(1);

try
{

//allow the user to see it the spreadsheet once genertated
excelApp.Visible = true;
carSales.Columns.ColumnWidth = 21.71;
//create headers in the columns
carSales.get_Range("A1",missing).Value2 = "Car Make";
carSales.get_Range("A1",missing).Font.Bold = true;
carSales.get_Range("B1",missing).Value2 = "VIN Number";

//get each record being passed in
start on the 3rd row of the spreadsheet
x = 3;
for (int i = 1; i <= carMake.length; i++)
{
carSales.get_range("A" + x.ToString(),missing).Value2 =
carMake;
//go to next row if applicable
x+=1;
}
}
catch (Excpetion ex)
{

}






Nicholas Paldino said:
NuB,

You still aren't showing the code that you are using to generate a
file. What you are showing is just something that increments the value in
ranges.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

NuB said:
I've tried this and its not working 100%
it either gives me the last record or just generates a file for each
one.
now i'm generating an excel sheet on the fly. I have it working in one
app, but that it reading a file directly, now I need to pass in the
information and its causing me some pain. Its either giving me the last
record passed in, or generating an file for each record.


for (int i = 1; i <= carMake.length; i++)
{
newSheet.get_range("A" + x.ToString(),missing).Value2 = carMake;
x+=1;
}

in message NuB,

Can you show the code you are using? It would seem you probably are
initializing your file stream (or file writer) in a loop, and creating
a new one through each iteration?

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

"NuB" <CSharpCoder> wrote in message
I'm passing in an array and I need to write them to a text file. I'm
getting the data in fine but instead of writing it all to one file it
generates a seperate file for each item. How can I put each item onto
the same file.


comes in like
BMW Lexus Chevy Saab

and its generating a file for
BMW Lexux Chevy Sabb

I need all of these on the same file
 
because i'm not saving it, its generated on the fly, the user sees it and
they can do whatever they want, close it after, save it, print, etc.


Nicholas Paldino said:
NuB,

This can't be doing it, as there is no call to save the file.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

NuB said:
how about this: this is generating the new file
// instance of excel
Excel.Application newExcel= new Excel.Application();
Excel.Workbook newWorkBook=
excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Excel._Worksheet carSales = (Excel._Worksheet)
excelBook.Worksheets.get_Item(1);

try
{

//allow the user to see it the spreadsheet once genertated
excelApp.Visible = true;
carSales.Columns.ColumnWidth = 21.71;
//create headers in the columns
carSales.get_Range("A1",missing).Value2 = "Car Make";
carSales.get_Range("A1",missing).Font.Bold = true;
carSales.get_Range("B1",missing).Value2 = "VIN Number";

//get each record being passed in
start on the 3rd row of the spreadsheet
x = 3;
for (int i = 1; i <= carMake.length; i++)
{
carSales.get_range("A" + x.ToString(),missing).Value2 =
carMake;
//go to next row if applicable
x+=1;
}
}
catch (Excpetion ex)
{

}






Nicholas Paldino said:
NuB,

You still aren't showing the code that you are using to generate a
file. What you are showing is just something that increments the value
in ranges.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

"NuB" <CSharpCoder> wrote in message
I've tried this and its not working 100%
it either gives me the last record or just generates a file for each
one.
now i'm generating an excel sheet on the fly. I have it working in one
app, but that it reading a file directly, now I need to pass in the
information and its causing me some pain. Its either giving me the last
record passed in, or generating an file for each record.


for (int i = 1; i <= carMake.length; i++)
{
newSheet.get_range("A" + x.ToString(),missing).Value2 = carMake;
x+=1;
}

"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote in message NuB,

Can you show the code you are using? It would seem you probably
are initializing your file stream (or file writer) in a loop, and
creating a new one through each iteration?

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

"NuB" <CSharpCoder> wrote in message
I'm passing in an array and I need to write them to a text file. I'm
getting the data in fine but instead of writing it all to one file it
generates a seperate file for each item. How can I put each item onto
the same file.


comes in like
BMW Lexus Chevy Saab

and its generating a file for
BMW Lexux Chevy Sabb

I need all of these on the same file
 
NuB,

Well, that's the case then. Instead of creating a new instance of
Excel.Application every time that function is called, you have to store the
reference and then set the values on sheet in the reference of the
application you store.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

NuB said:
because i'm not saving it, its generated on the fly, the user sees it and
they can do whatever they want, close it after, save it, print, etc.


Nicholas Paldino said:
NuB,

This can't be doing it, as there is no call to save the file.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

NuB said:
how about this: this is generating the new file
// instance of excel
Excel.Application newExcel= new Excel.Application();
Excel.Workbook newWorkBook=
excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Excel._Worksheet carSales = (Excel._Worksheet)
excelBook.Worksheets.get_Item(1);

try
{

//allow the user to see it the spreadsheet once genertated
excelApp.Visible = true;
carSales.Columns.ColumnWidth = 21.71;
//create headers in the columns
carSales.get_Range("A1",missing).Value2 = "Car Make";
carSales.get_Range("A1",missing).Font.Bold = true;
carSales.get_Range("B1",missing).Value2 = "VIN Number";

//get each record being passed in
start on the 3rd row of the spreadsheet
x = 3;
for (int i = 1; i <= carMake.length; i++)
{
carSales.get_range("A" + x.ToString(),missing).Value2 =
carMake;
//go to next row if applicable
x+=1;
}
}
catch (Excpetion ex)
{

}






in message NuB,

You still aren't showing the code that you are using to generate a
file. What you are showing is just something that increments the value
in ranges.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

"NuB" <CSharpCoder> wrote in message
I've tried this and its not working 100%
it either gives me the last record or just generates a file for each
one.
now i'm generating an excel sheet on the fly. I have it working in one
app, but that it reading a file directly, now I need to pass in the
information and its causing me some pain. Its either giving me the
last record passed in, or generating an file for each record.


for (int i = 1; i <= carMake.length; i++)
{
newSheet.get_range("A" + x.ToString(),missing).Value2 = carMake;
x+=1;
}

"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote in message NuB,

Can you show the code you are using? It would seem you probably
are initializing your file stream (or file writer) in a loop, and
creating a new one through each iteration?

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

"NuB" <CSharpCoder> wrote in message
I'm passing in an array and I need to write them to a text file. I'm
getting the data in fine but instead of writing it all to one file
it generates a seperate file for each item. How can I put each item
onto the same file.


comes in like
BMW Lexus Chevy Saab

and its generating a file for
BMW Lexux Chevy Sabb

I need all of these on the same file
 
and thats my question how would i do that?

Nicholas Paldino said:
NuB,

Well, that's the case then. Instead of creating a new instance of
Excel.Application every time that function is called, you have to store
the reference and then set the values on sheet in the reference of the
application you store.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

NuB said:
because i'm not saving it, its generated on the fly, the user sees it and
they can do whatever they want, close it after, save it, print, etc.


Nicholas Paldino said:
NuB,

This can't be doing it, as there is no call to save the file.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

"NuB" <CSharpCoder> wrote in message
how about this: this is generating the new file
// instance of excel
Excel.Application newExcel= new Excel.Application();
Excel.Workbook newWorkBook=
excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Excel._Worksheet carSales = (Excel._Worksheet)
excelBook.Worksheets.get_Item(1);

try
{

//allow the user to see it the spreadsheet once genertated
excelApp.Visible = true;
carSales.Columns.ColumnWidth = 21.71;
//create headers in the columns
carSales.get_Range("A1",missing).Value2 = "Car Make";
carSales.get_Range("A1",missing).Font.Bold = true;
carSales.get_Range("B1",missing).Value2 = "VIN Number";

//get each record being passed in
start on the 3rd row of the spreadsheet
x = 3;
for (int i = 1; i <= carMake.length; i++)
{
carSales.get_range("A" + x.ToString(),missing).Value2 =
carMake;
//go to next row if applicable
x+=1;
}
}
catch (Excpetion ex)
{

}






"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote in message NuB,

You still aren't showing the code that you are using to generate a
file. What you are showing is just something that increments the value
in ranges.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

"NuB" <CSharpCoder> wrote in message
I've tried this and its not working 100%
it either gives me the last record or just generates a file for each
one.
now i'm generating an excel sheet on the fly. I have it working in
one app, but that it reading a file directly, now I need to pass in
the information and its causing me some pain. Its either giving me
the last record passed in, or generating an file for each record.


for (int i = 1; i <= carMake.length; i++)
{
newSheet.get_range("A" + x.ToString(),missing).Value2 = carMake;
x+=1;
}

"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote in message NuB,

Can you show the code you are using? It would seem you probably
are initializing your file stream (or file writer) in a loop, and
creating a new one through each iteration?

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

"NuB" <CSharpCoder> wrote in message
I'm passing in an array and I need to write them to a text file.
I'm getting the data in fine but instead of writing it all to one
file it generates a seperate file for each item. How can I put each
item onto the same file.


comes in like
BMW Lexus Chevy Saab

and its generating a file for
BMW Lexux Chevy Sabb

I need all of these on the same file
 
Back
Top