Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by leonida · Aug 02, 2012 at 03:25 PM · editorbuildexcel

read an excel file works only in the editor,not in the build

hello, here's my code for read from excel file. editor works fine but in the build the excel file is not read.

when i work in the editor the file is in the folder

 c:\projectname\1.xls

in the build:

 c:\1.xls
 c:\project_Data\ 1.xls


 using UnityEngine;
 using System.Collections;
 using System; 
 using System.Data; 
 using System.Data.Odbc; 
 
 public class ExcelReader : MonoBehaviour
 {
     String something;
     public String Filename="1";
     
     void Start ()
     {
         readXLS(Filename); 
     }
  
     void readXLS(String Filename)
     {
         // Must be saved as excel 2003 workbook, not 2007, mono issue really
         string con = "Driver={Microsoft Excel Driver (*.xls)}; DriverId=790; Dbq="+Filename+";";
         string yourQuery = "SELECT * FROM [Foglio1$]"; 

         OdbcConnection oCon = new OdbcConnection(con); 
         
         OdbcCommand oCmd = new OdbcCommand(yourQuery, oCon);

         DataTable dtYourData = new DataTable("YourData"); 
         
         oCon.Open(); 
         
         OdbcDataReader rData = oCmd.ExecuteReader(); 
         
         dtYourData.Load(rData); 
         
         rData.Close(); 
         
         oCon.Close(); 
         
         if(dtYourData.Rows.Count > 0) 
         { 
             prova = dtYourData.Rows[0][dtYourData.Columns[1].ColumnName].ToString(); 
             if (something == "DESTROY!")
                 Destroy(GameObject.Find("Cube"));
             print(something);
         }
     }
 }
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Aug 02, 2012 at 04:39 PM 0
Share

What is "prova" and where is "something" set? OR should "prova" be "something"?

Why do you want to read xls? Use a more general format like xml or csv if you want to work with excel. xml or csv can easily be read on all platforms. The odbc driver for excel does only work for windows builds.

2 Replies

· Add your reply
  • Sort: 
avatar image
-2

Answer by vickartinson39 · Jun 16, 2013 at 07:42 PM

Read excel files by the use of excel repair file

Apply http://www.excel2007repair.excelrepairtoolbox.com contains a lot of effective solutions

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Owen-Reynolds · Aug 02, 2012 at 04:09 PM

The build tries to keep small by stripping out anything it doesn't know you're using. really nice feature. It checks for anything on a gameObject, Material ... and anything which has been dragged into a public variable in an Inspector. But, it can't "see" things which are only accessed in code.

So, it's probably purposely not including your file.

The Unity work-around for that is to put anything like that into a folder named Resources. Anything in there is always included in the build. Not sure if caps matter, or it needs to be a single top-level Resources folder. But you should be able to just examine the new build-folder and see if it's there.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Aug 02, 2012 at 04:25 PM 0
Share

Code stripping is a mobile only feature afaik. On all other platforms everything is included, even classes or scripts that aren't used anywhere.

@leonida: $$anonymous$$y first question is, what target platform do you try to build for?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

read XML work in editor but not in final build 2 Answers

Distribute terrain in zones 3 Answers

Create/Save a build or version in case of mistakes ? 1 Answer

Unity Scene File in Build Question 1 Answer

Create custom warning dialog on build, if a script or gameobject exists in the scene 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges