How can I set Separator?


Hi....everyone
my code :
Dim a As Aspose.Cells.TxtSaveOptions = New Aspose.Cells.TxtSaveOptions()
a.Separator = Chr(0)
wb.Save(Me.Response, "Report.txt", Aspose.Cells.ContentDisposition.Attachment, a)

I want Excel to .txt file
but when output .txt file
i see Each data with a blank space
but my code is chr(0)
i want each data no blank space
ex :
i want "1234567890"
i don't want "1 2 3 4 5 6 7 8 9 0"
so how can i do??? to set a.Separator
default Separator is ","
thank you...
Michael From Taiwan

Hi Michael,


Thank you for contacting Aspose support.

Could you please clarify the scenario further? What I have understood from your post is that you do not wish to use any separator while exporting spreadsheet to Text format. If this is correct then I am afraid, it may not be possible, that is; you have to specify any separator while exporting the spreadsheet to Text/CSV format. You may check this by setting the TxtSaveOptions.Separator property to vbNullChar (equals Char(0)) and you will notice that values are separated with spaces.

This is my Code :
Dim nospace As Aspose.Cells.TxtSaveOptions = New Aspose.Cells.TxtSaveOptions()
nospace.Separator = Chr(0)
wb.Save(Me.Response, "Report.txt", Aspose.Cells.ContentDisposition.Attachment, nospace)

I do not want any Separator(include space)
so....
How can I do to set separator ???
nospace.Separator = Chr(?)

I want execel to Text ,below :
1234567890 (Yes)

I do not want ,below :
1,2,3,4,5,6,7,8,9,0 (NO)
1 2 3 4 5 6 7 8 9 0 (NO)
1;2;3;4;5;6;7;8;9;0 (NO)

if excel file content below :
AA BB CC DD EE FF
GG HH II JJ KK LL

save to txt below :
AABBCCDDEEFF
GGHHIIJJKKLL

thank you...

Michael From Taiwan

Hi Michael,

Thanks for your posting and using Aspose.Cells.

As a workaround, please see the following sample code. I have also attached the output txt file generated by it for your reference. Let us know your feedback.

C#
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

//First Row
worksheet.Cells[“A1”].PutValue(1);
worksheet.Cells[“B1”].PutValue(10);
worksheet.Cells[“C1”].PutValue(11);
worksheet.Cells[“D1”].PutValue(12);
worksheet.Cells[“E1”].PutValue(13);
worksheet.Cells[“F1”].PutValue(14);
worksheet.Cells[“G1”].PutValue(15);

//Second Row
worksheet.Cells[“A2”].PutValue(1);
worksheet.Cells[“B2”].PutValue(10);
worksheet.Cells[“C2”].PutValue(11);
worksheet.Cells[“D2”].PutValue(12);
worksheet.Cells[“E2”].PutValue(13);
worksheet.Cells[“F2”].PutValue(14);
worksheet.Cells[“G2”].PutValue(15);

TxtSaveOptions opts = new TxtSaveOptions();
opts.Separator = ‘,’;

MemoryStream ms = new MemoryStream();

workbook.Save(ms, opts);

ms.Position = 0;
StreamReader sr = new StreamReader(ms);
String str = sr.ReadToEnd();
str = str.Replace(",", “”);

File.WriteAllText(“output.txt”, str);

File.WriteAllText("output.txt", str);

this code can popup "save as" Dialog ??
let user download output file??

Hi,

Thanks for your feedback and using Aspose.Cells.

You can directly send your string as a text file without the need of Aspose.Cells. Please see the following code for your reference to see how to achieve it.

I have also attached the code file and aspx page for your reference.

C#

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Aspose.Cells;
using System.IO;
using System.Text;

public partial class MyTextOutput : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

//First Row
worksheet.Cells[“A1”].PutValue(1);
worksheet.Cells[“B1”].PutValue(10);
worksheet.Cells[“C1”].PutValue(11);
worksheet.Cells[“D1”].PutValue(12);
worksheet.Cells[“E1”].PutValue(13);
worksheet.Cells[“F1”].PutValue(14);
worksheet.Cells[“G1”].PutValue(15);

//Second Row
worksheet.Cells[“A2”].PutValue(1);
worksheet.Cells[“B2”].PutValue(10);
worksheet.Cells[“C2”].PutValue(11);
worksheet.Cells[“D2”].PutValue(12);
worksheet.Cells[“E2”].PutValue(13);
worksheet.Cells[“F2”].PutValue(14);
worksheet.Cells[“G2”].PutValue(15);

TxtSaveOptions opts = new TxtSaveOptions();
opts.Separator = ‘,’;

MemoryStream ms = new MemoryStream();

workbook.Save(ms, opts);

ms.Position = 0;

ms.Position = 0;
StreamReader sr = new StreamReader(ms);
String str = sr.ReadToEnd();
str = str.Replace(",", “”);

Response.Clear();
Response.Buffer = true;
Response.ContentType = “text/plain”;
Response.AppendHeader(“content-disposition”, “attachment;filename=output.txt”);
Response.Write(str);
Response.End();
}
}