I face small problem when i read data from excel file. Actully i am using COM for read and write into excel file data. My excel file have a data like date "12-16-2010" or some nos like "1234567890", then After reading i am getting the data like "#####" and "12E10" somethink like that. I know the problem, Actully my excel file do not have autofit. When i open my excel file manually, we can see "####" instead of date. If i increate the cell size then my code works fine. My question is how to resolve this from code. I try to use AutoFit(), But it is not working and it takes more time also. Guys tell your ideas :)
After reading your question, I've opened the Excel to do a test. And I think the problem is caused by
the cell format. First, I want to describe my opinion about the problem so that you can check to see whether I have misunderstood you. 1. When I open the Excel. I set the cell A1's format into Date. Then Enter the information "1234567890", I will get the result like "#########" 2. When the cell format is set to Scientific and we will get the data like "12E10" etc. So I've written a Workbook project. My develop environment targeting VS2010 and Office2010. The code is like that: private void Sheet1_Startup(object sender, System.EventArgs e) { Excel.Application thisExcelApp = this.Application; Excel.Range rng = thisExcelApp.get_Range("A1",missing); rng.NumberFormat = "@"; double st = rng.Value; Excel.Range rng2 = thisExcelApp.get_Range("B1",missing); rng2.NumberFormat = "@"; double st2 = rng2.Value; MessageBox.Show(st.ToString()); MessageBox.Show(st2.ToString()); } I've set the cell A1's format into Date while B1's format is Scientific. So when I enter the data "1234567890" and "12345678",
they will show in the Excel worksheet like that: Then I run the program, change the format of A1 and B1 to Text. Then show them in the MessageBox. The result is: Please check to see if it will solve the problem. Any further questions or if I misunderstood you, please feel free to contact. Thank you! Best Regards, Amy Li Thanks for your solution and mark as answer. Actully i solved this problem. And I forget to raise this post otherwise i will post my solution. I follow the bellow code ((Range) this.myWorkSheet.Columns[colIndex, Type.Missing]).NumberFormat = "General"; Your code also do the same think, When compare to this, you code will works fast i think. Can you plz rate my coding skill. If you feel this is unwanted content plz remove this statement. And i need one more help, Plz check the bellow forum and plz respond |
|