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.

Wed May 05, 2021 10:26 am

Hi,
I'm creating a report from multiple excel & word files.
I have an excel file with conditional formatting to hide 0 values.
I want to copy this excel to word file, but when I read cell.NumberText I get "0".
I would like to check is there a conditional formatting and apply it before copying.

Can anyone please explain me how?
Thanks in advance!

nickmargu
 
Posts: 4
Joined: Wed May 05, 2021 10:19 am

Thu May 06, 2021 6:48 am

Hello,

Thank you for your inquiry. To help us investigate and solve your issue more quickly and accurately, please provide the your input Excel file and the Word file you expected. You could attach it here or send to us via email (support@e-iceblue.com). Thanks in advance.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1648
Joined: Wed Apr 07, 2021 2:50 am

Mon May 10, 2021 1:06 pm

hi attached sample files
Attachments
example.zip
example word and excel
(23.54 KiB) Downloaded 172 times

nickmargu
 
Posts: 4
Joined: Wed May 05, 2021 10:19 am

Tue May 11, 2021 8:33 am

Hello,

Thanks for your sharing.
An easy way to achieve your need is to set the cell.NumberValue of "0" as empty, then copy to excel file. See the code below.
Code: Select all
...
if (xCell.NumberValue == 0)
{
    xCell.Value = "";
}
...

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1648
Joined: Wed Apr 07, 2021 2:50 am

Tue May 11, 2021 9:16 am

Hi
thanks for your suggestion.
I want this behavior to be applied only when source excel has the conditional formatting definition.
Is there a way to check for conditional formatting in code?

nickmargu
 
Posts: 4
Joined: Wed May 05, 2021 10:19 am

Tue May 11, 2021 11:11 am

Hi,

Thanks for your quick reply.
Our Spire.XLS provides the cell.HasConditionFormats to judge if a cell contains condition format. In your Excel file, these cells are applied condition format: =$A$4:$D$5,$A$32:$L$32,$A$22:$J$29,$A$34:$L$34,$A$16:$B$16,$A$20:$B$21,$A$6:$J$15,$A$17:$J$19. I think your ultimate goal is to get the style of the conditional formats, and apply the style when copying to Word, sorry to tell that the style of conditional formatting is calculated dynamically, there is no way to obtain it.
If there is any misunderstanding, please provide more information.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Wed May 19, 2021 9:33 am

Hello,

Greetings from e-iceblue.
How is your issue going? Can you give us some feedback at your convenience? Thanks in advance.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1648
Joined: Wed Apr 07, 2021 2:50 am

Thu May 20, 2021 10:42 am

just used your suggestion to use
Code: Select all
 if (number == 0 && cell.HasConditionFormats)
               value = string.Empty;

nickmargu
 
Posts: 4
Joined: Wed May 05, 2021 10:19 am

Fri May 21, 2021 2:07 am

Hello,

Thank you for your feedback.
If you have other questions about using Spire.XLS in the future, please feel free to contact us.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1648
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.XLS