使用PHPExcel将excel文件的内容导入MySQL数据库(格式问题)(Using PHPExcel to import contents of excel file into MySQL database (format problems))
我正在将Excel 2007文件的内容导入MySQL数据库,但电子表格中的日期字段是自定义日期格式(dd-mmm-yy)。 我无法将其更改为文本,因为客户端将上传它,因此不可行。 当我导入文件的内容时,它会将日期作为数字插入,例如40978而不是09年1月12日。 我知道更改字段的数据库表格格式将没有效果,因为它的excels formatitng但有没有人知道这方面的方法? 不改变电子表格的格式?
I'm importing the contents of an Excel 2007 file into a MySQL database but the date field in the spreadsheet is a custom date format (dd-mmm-yy). I cannot change this to text because a client will be uploading it so it is not feasible. When I import the contents of the file it inserts the date as a number e.g. 40978 instead of 12-Jan-09. I know that changing the database table format of the field will have no effect as its excels formatitng but does anyone know a way around this? Without changing the format of the spreadsheet?
原文:https://stackoverflow.com/questions/5406253
最满意答案
如果您想要一个安全的解决方案,需要更少的样板代码而不是打开可选项,那么解决此问题就没有简单的解决方案。 抛出错误而不是返回nil绝对是一个坏主意,因为处理错误需要更多的样板代码而不是安全地展开可选项。
您不能覆盖现有的变量类型,因此您也不能使
GKComponent.entity
非可选。使用保护语句进行可选绑定,这样可以最小化用于展开值的样板代码。
There is no easy solution to solve this issue if you want a safe solution that requires less boilerplate code than unwrapping an optional. Throwing an error instead of returning nil is definitely a bad idea, since handling an error requires even more boilerplate code than safely unwrapping an optional.
You cannot override existing variables types, so you cannot make
GKComponent.entity
non-optional either.Use guard statements for optional binding, that way you can minimise the boilerplate code for unwrapping the value.
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
更新 苹果现在已经添加了一个合并运算符: var unwrappedValue = optionalValue ?? defaultValue 在这种情况下,三位运算符是您的朋友 var unwrappedValue = optionalValue ? optionalValue! : defaultValue 您还可以为可选枚举提供自己的扩展名: extension Optional { func or(defaultValue: T) -> T { switch(self) ...
-
你可以简单地使用Optional的map(_:)方法,如果它是非零的,它将返回包含给定变换的值,否则它将返回nil 。 let f : Float? = 2 // If f is non-nil, return the result from the wrapped value passed to Double(_:), // else return nil. let d = f.map { Double($0) } 正如您在下面的评论中指出的那样,也可以说: let d = f.map(Double. ...
-
您应该将可选闭包括在括号中。 这将适当地适用范围? 运营商。 func then(onFulfilled: ()->(), onReject: (()->())?){ if let callableRjector = onReject { // do stuff! } } You should enclose the optional closure in parentheses. This will properly scope the ? operator ...
-
如果您想要一个安全的解决方案,需要更少的样板代码而不是打开可选项,那么解决此问题就没有简单的解决方案。 抛出错误而不是返回nil绝对是一个坏主意,因为处理错误需要更多的样板代码而不是安全地展开可选项。 您不能覆盖现有的变量类型,因此您也不能使GKComponent.entity非可选。 使用保护语句进行可选绑定,这样可以最小化用于展开值的样板代码。 There is no easy solution to solve this issue if you want a safe solution that r ...
-
结论是正确的 - let是一个独立但有用的构造。 在上下文中,仅在if-body内部引入绑定,并且仅当绑定值不是-nil时才执行if-body。 (从技术上讲,它解开了可选的绑定。) let不影响如何处理右侧表达式(有或没有链接)。 例如,如果someMasterObject是可选的/无,它会失败,不“链” - 即使有。 当一个或另一个(或两者)更“正确”取决于情况:例如。 链接的内容以及纠正措施应该是什么。 例如,如果someMasterObject可能为零,我们可能会使用以下链接和let 。 还要注意返 ...
-
当我向下滚动一个certian时,我试图让div出现?(I am trying to make a div appear when i scroll down a certian amont ?)[2023-02-25]
您应该尝试使用窗口而不是文档: $(window).on('scroll', function() { ... }); 其余代码看起来是正确的,但在javascript中你选择了类filmandcrew的div,而你的css用id filmandcrew为div设置样式。 You should try with window instead of document : $(window).on('scroll', function() { ... }); The rest of your code lo ... -
由于单点调度(物理世界的联系代表),碰撞处理很难在实体组件架构中很好地处理。 但您可以使用该点来整理所涉及的实体并将联系人消息分派给正确的组件。 Apple的DemoBots示例代码就是一个例子。 以下是他们如何做到的快速摘要: 需要联系处理的SK节点使用一个特殊的子类EntityNode ,它为节点的拥有实体( GKEntity或某个子类)添加一个反向引用。 在didBeginContact ,理清联系人是否需要处理以及由谁处理。 DemoBots通过创建ColliderType结构来实现这一点,该结构有 ...
-
无法在swift中展开可选项(can't unwrap optional in swift)[2022-11-10]
这里的可选值是PFUser.currentUser()的返回值, PFUser.currentUser()不是objectId 。 您需要稍微更改,因为当前用户可能不存在。 就像是... if let user = PFUser.currentUser()! { let objectID = user.objectId } 或者其他的东西。 不太确定,因为我还没有正确进入Swift。 The optional here is the return value from PFUser.current ...