Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Mon Aug 17, 2020 11:43 am

I have already give the file PFA screenshot in the column "U" as you can see it is going to other line, there is text after indrapu but its not visible.

That is creating problem in formatting
Last edited by gauti0710 on Tue Aug 18, 2020 8:53 am, edited 1 time in total.

gauti0710
 
Posts: 22
Joined: Thu Aug 06, 2020 2:12 pm

Mon Aug 17, 2020 1:38 pm

I have to replace the column with a replace but for that i have made a code but it is not taking more than one value

for (int iRow = 12; iRow < 200; iRow++)
{
var StringValue = workbook.Worksheets[0].Cells[iRow, 2].StringValue;
StringValue = StringValue.Replace('\n', ' ');

workbook.Worksheets[0].Cells[iRow, 2].Value = StringValue;
}

can you please give me the code to replace \n with " "

That will be helpful

gauti0710
 
Posts: 22
Joined: Thu Aug 06, 2020 2:12 pm

Mon Aug 17, 2020 2:23 pm

I have already provided the file i have created code as well but that code is not working in spire

i want to replace \n with space for particular column PFB code.



PFA screenshot of the column after indrapur it is not visible

for (int iRow = 12; iRow < 200; iRow++)
{
var StringValue = workbook.Worksheets[0].Cells[iRow, 20].StringValue;
//StringValue = Regex.Replace(StringValue, @"\s+", " ");
StringValue = StringValue.Replace('\n', ' ');

workbook.Worksheets[0].Cells[iRow, 20].Value = StringValue;
}

gauti0710
 
Posts: 22
Joined: Thu Aug 06, 2020 2:12 pm

Tue Aug 18, 2020 7:56 am

Hello ,

In this case there is problem of carriage return do you know how to replace that in whole column with space?

gauti0710
 
Posts: 22
Joined: Thu Aug 06, 2020 2:12 pm

Tue Aug 18, 2020 9:19 am

Do you have any update on this?

gauti0710
 
Posts: 22
Joined: Thu Aug 06, 2020 2:12 pm

Tue Aug 18, 2020 9:58 am

Hi

Thanks for your detailed information.
Please refer to the following code to replace the "\n" with space. If the problem persists, please porvide your Excel file for further investigation. Thanks in advance.
Code: Select all
Workbook workbook = new Workbook();
workbook.LoadFromFile("test.xlsx");
var StringValue = workbook.Worksheets[0].Range[1,1].Text;
StringValue = StringValue.Replace('\n', ' ');
workbook.Worksheets[0].Range[1, 1].Value = StringValue;
workbook.SaveToFile("result.xlsx");
System.Diagnostics.Process.Start("result.xlsx");



Sincerely,
Lynn
E-iceblue support team
User avatar

lynn.zhang
 
Posts: 57
Joined: Mon Jul 27, 2020 2:27 am

Tue Aug 18, 2020 10:50 am

I am getting error string value was null. After using the above code

gauti0710
 
Posts: 22
Joined: Thu Aug 06, 2020 2:12 pm

Tue Aug 18, 2020 3:49 pm

I have already shared the xls in my posts please check.

gauti0710
 
Posts: 22
Joined: Thu Aug 06, 2020 2:12 pm

Wed Aug 19, 2020 6:22 am

Did you check xls?

gauti0710
 
Posts: 22
Joined: Thu Aug 06, 2020 2:12 pm

Wed Aug 19, 2020 8:53 am

Hi,

Thanks for your feedback.
In previous code I posted, the Range[1,1] represents the first cell ("A1") in Excel sheet, you have to modify the corresponding cells according to your own document. I used the Excel you sent me earlier to replace ‘\n’ of the Address column with space, no error happened. Below is my code and attached my generated file for your better reference.
Code: Select all
  Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"XLStocsv.XLS");
            for (int i = 13; i < 69; i++)
            {
                var StringValue = workbook.Worksheets[0].Range[i,16 ].Text;
                StringValue = StringValue.Replace('\n', ' ');
                workbook.Worksheets[0].Range[i, 16].Value = StringValue;   
            }
            workbook.SaveToFile("result.xlsx");
            System.Diagnostics.Process.Start("result.xlsx");


Sincerely,
Lynn
E-iceblue support team
Attachments
test.rar
(19.94 KiB) Downloaded 520 times
User avatar

lynn.zhang
 
Posts: 57
Joined: Mon Jul 27, 2020 2:27 am

Wed Aug 19, 2020 3:54 pm

It is working fine thanks a lot. :)

gauti0710
 
Posts: 22
Joined: Thu Aug 06, 2020 2:12 pm

Thu Aug 20, 2020 2:19 am

Hi,

Thanks for your feedback.
Glad to hear that your issue has been resolved. If you need further assistance, please feel free to write back.
Wish you all the best!

Sincerely,
Lynn
E-iceblue support team
User avatar

lynn.zhang
 
Posts: 57
Joined: Mon Jul 27, 2020 2:27 am

Return to Spire.XLS